mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Dont consider fields that are forced unstable due to -Zforce-unstable-if-unmarked to be uninhabited
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
//! This code should only compile in modules where the uninhabitedness of `Foo`
|
||||
//! is visible.
|
||||
|
||||
use rustc_span::sym;
|
||||
use rustc_type_ir::TyKind::*;
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -90,7 +91,13 @@ pub fn inhabited_predicate(
|
||||
// `let pred = pred.or(InhabitedPredicate::IsUnstable(field.did));`
|
||||
// but this is unnecessary for now, since it would only affect nightly-only
|
||||
// code or code within the standard library itself.
|
||||
if tcx.lookup_stability(field.did).is_some_and(|stab| stab.is_unstable()) {
|
||||
// HACK: We filter out `rustc_private` fields since with the flag
|
||||
// `-Zforce-unstable-if-unmarked` we consider all unmarked fields to be
|
||||
// unstable when building the compiler.
|
||||
if tcx
|
||||
.lookup_stability(field.did)
|
||||
.is_some_and(|stab| stab.is_unstable() && stab.feature != sym::rustc_private)
|
||||
{
|
||||
return InhabitedPredicate::True;
|
||||
}
|
||||
let pred = tcx.type_of(field.did).instantiate_identity().inhabited_predicate(tcx);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
|
||||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, sym};
|
||||
|
||||
use crate::constructor::Constructor::*;
|
||||
use crate::constructor::{
|
||||
@@ -232,10 +232,10 @@ fn reveal_and_alloc<'a, 'tcx>(
|
||||
let is_visible =
|
||||
adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
|
||||
let is_uninhabited = cx.is_uninhabited(*ty);
|
||||
let is_unstable = cx
|
||||
.tcx
|
||||
.lookup_stability(field.did)
|
||||
.is_some_and(|stab| stab.is_unstable());
|
||||
let is_unstable =
|
||||
cx.tcx.lookup_stability(field.did).is_some_and(|stab| {
|
||||
stab.is_unstable() && stab.feature != sym::rustc_private
|
||||
});
|
||||
let skip = is_uninhabited && (!is_visible || is_unstable);
|
||||
(ty, PrivateUninhabitedField(skip))
|
||||
});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
enum Void {}
|
||||
|
||||
fn demo(x: Pin<Void>) {
|
||||
match x {}
|
||||
//~^ ERROR non-exhaustive patterns
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,19 @@
|
||||
error[E0004]: non-exhaustive patterns: type `Pin<Void>` is non-empty
|
||||
--> $DIR/uninhabited-pin-field.rs:6:11
|
||||
|
|
||||
LL | match x {}
|
||||
| ^
|
||||
|
|
||||
note: `Pin<Void>` defined here
|
||||
--> $SRC_DIR/core/src/pin.rs:LL:COL
|
||||
= note: the matched value is of type `Pin<Void>`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
|
||||
|
|
||||
LL ~ match x {
|
||||
LL + _ => todo!(),
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
@@ -14,7 +14,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
||||
|
|
||||
LL ~ match x {
|
||||
LL + _ => todo!(),
|
||||
LL + }
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
Reference in New Issue
Block a user