File tree 4 files changed +53
-0
lines changed
compiler/rustc_middle/src/ty/inhabitedness
4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,15 @@ impl<'tcx> VariantDef {
84
84
InhabitedPredicate :: all (
85
85
tcx,
86
86
self . fields . iter ( ) . map ( |field| {
87
+ // Unstable fields are always considered to be inhabited. In the future,
88
+ // this could be extended to be conditional on the field being unstable
89
+ // only within the module that's querying the inhabitedness, like:
90
+ // `let pred = pred.or(InhabitedPredicate::IsUnstable(field.did));`
91
+ // but this is unnecessary for now, since it would only affect nightly-only
92
+ // code or code within the standard library itself.
93
+ if tcx. lookup_stability ( field. did ) . is_some_and ( |stab| stab. is_unstable ( ) ) {
94
+ return InhabitedPredicate :: True ;
95
+ }
87
96
let pred = tcx. type_of ( field. did ) . instantiate_identity ( ) . inhabited_predicate ( tcx) ;
88
97
if adt. is_enum ( ) {
89
98
return pred;
Original file line number Diff line number Diff line change
1
+ #![ feature( staged_api) ]
2
+ #![ stable( feature = "stable" , since = "1.0.0" ) ]
3
+
4
+ #[ stable( feature = "stable" , since = "1.0.0" ) ]
5
+ pub struct Foo < T > {
6
+ #[ unstable( feature = "unstable" , issue = "none" ) ]
7
+ pub field : T ,
8
+ }
Original file line number Diff line number Diff line change
1
+ //@ aux-build: staged-api.rs
2
+
3
+ extern crate staged_api;
4
+
5
+ use staged_api:: Foo ;
6
+
7
+ enum Void { }
8
+
9
+ fn demo ( x : Foo < Void > ) {
10
+ match x { }
11
+ //~^ ERROR non-exhaustive patterns
12
+ }
13
+
14
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0004]: non-exhaustive patterns: type `Foo<Void>` is non-empty
2
+ --> $DIR/uninhabited-unstable-field.rs:10:11
3
+ |
4
+ LL | match x {}
5
+ | ^
6
+ |
7
+ note: `Foo<Void>` defined here
8
+ --> $DIR/auxiliary/staged-api.rs:5:1
9
+ |
10
+ LL | pub struct Foo<T> {
11
+ | ^^^^^^^^^^^^^^^^^
12
+ = note: the matched value is of type `Foo<Void>`
13
+ help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
14
+ |
15
+ LL ~ match x {
16
+ LL + _ => todo!(),
17
+ LL + }
18
+ |
19
+
20
+ error: aborting due to 1 previous error
21
+
22
+ For more information about this error, try `rustc --explain E0004`.
You can’t perform that action at this time.
0 commit comments