Skip to content

Commit 08b30f9

Browse files
authored
Unrolled build for #144216
Rollup merge of #144216 - Nadrieril:revert-pin-hack, r=compiler-errors Don't consider unstable fields always-inhabited This reverts the hack in #133889 now that `Pin`'s field is no longer public. Fixes #143468. r? ```@compiler-errors```
2 parents e05ab47 + 3567ab1 commit 08b30f9

File tree

7 files changed

+71
-72
lines changed

7 files changed

+71
-72
lines changed

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
//! This code should only compile in modules where the uninhabitedness of `Foo`
4444
//! is visible.
4545
46-
use rustc_span::sym;
4746
use rustc_type_ir::TyKind::*;
4847
use tracing::instrument;
4948

@@ -85,21 +84,6 @@ impl<'tcx> VariantDef {
8584
InhabitedPredicate::all(
8685
tcx,
8786
self.fields.iter().map(|field| {
88-
// Unstable fields are always considered to be inhabited. In the future,
89-
// this could be extended to be conditional on the field being unstable
90-
// only within the module that's querying the inhabitedness, like:
91-
// `let pred = pred.or(InhabitedPredicate::IsUnstable(field.did));`
92-
// but this is unnecessary for now, since it would only affect nightly-only
93-
// code or code within the standard library itself.
94-
// HACK: We filter out `rustc_private` fields since with the flag
95-
// `-Zforce-unstable-if-unmarked` we consider all unmarked fields to be
96-
// unstable when building the compiler.
97-
if tcx
98-
.lookup_stability(field.did)
99-
.is_some_and(|stab| stab.is_unstable() && stab.feature != sym::rustc_private)
100-
{
101-
return InhabitedPredicate::True;
102-
}
10387
let pred = tcx.type_of(field.did).instantiate_identity().inhabited_predicate(tcx);
10488
if adt.is_enum() {
10589
return pred;

compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::ty::{
1616
};
1717
use rustc_middle::{bug, span_bug};
1818
use rustc_session::lint;
19-
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, sym};
19+
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
2020

2121
use crate::constructor::Constructor::*;
2222
use crate::constructor::{
@@ -238,10 +238,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
238238
let is_visible =
239239
adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
240240
let is_uninhabited = cx.is_uninhabited(*ty);
241-
let is_unstable = cx.tcx.lookup_stability(field.did).is_some_and(|stab| {
242-
stab.is_unstable() && stab.feature != sym::rustc_private
243-
});
244-
let skip = is_uninhabited && (!is_visible || is_unstable);
241+
let skip = is_uninhabited && !is_visible;
245242
(ty, PrivateUninhabitedField(skip))
246243
});
247244
cx.dropless_arena.alloc_from_iter(tys)

tests/ui/uninhabited/auxiliary/staged-api.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ pub struct Foo<T> {
66
#[unstable(feature = "unstable", issue = "none")]
77
pub field: T,
88
}
9+
10+
#[unstable(feature = "my_coro_state", issue = "none")]
11+
pub enum MyCoroutineState<Y, R> {
12+
Yielded(Y),
13+
Complete(R),
14+
}

tests/ui/uninhabited/uninhabited-unstable-field.current.stderr

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/ui/uninhabited/uninhabited-unstable-field.exhaustive.stderr

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
//@ aux-build: staged-api.rs
2-
//@ revisions: current exhaustive
3-
2+
//! The field of `Pin` used to be public, which would cause `Pin<Void>` to be uninhabited. To remedy
3+
//! this, we temporarily made it so unstable fields are always considered inhabited. This has now
4+
//! been reverted, and this file ensures that we don't special-case unstable fields wrt
5+
//! inhabitedness anymore.
46
#![feature(exhaustive_patterns)]
7+
#![feature(never_type)]
8+
#![feature(my_coro_state)] // Custom feature from `staged-api.rs`
9+
#![deny(unreachable_patterns)]
510

611
extern crate staged_api;
712

8-
use staged_api::Foo;
13+
use staged_api::{Foo, MyCoroutineState};
914

1015
enum Void {}
1116

1217
fn demo(x: Foo<Void>) {
1318
match x {}
14-
//~^ ERROR non-exhaustive patterns
1519
}
1620

17-
// Ensure that the pattern is not considered unreachable.
21+
// Ensure that the pattern is considered unreachable.
1822
fn demo2(x: Foo<Void>) {
1923
match x {
20-
Foo { .. } => {}
24+
Foo { .. } => {} //~ ERROR unreachable
2125
}
2226
}
2327

2428
// Same as above, but for wildcard.
2529
fn demo3(x: Foo<Void>) {
26-
match x { _ => {} }
30+
match x {
31+
_ => {} //~ ERROR unreachable
32+
}
33+
}
34+
35+
fn unstable_enum(x: MyCoroutineState<i32, !>) {
36+
match x {
37+
MyCoroutineState::Yielded(_) => {}
38+
}
39+
match x {
40+
MyCoroutineState::Yielded(_) => {}
41+
MyCoroutineState::Complete(_) => {} //~ ERROR unreachable
42+
}
2743
}
2844

2945
fn main() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: unreachable pattern
2+
--> $DIR/uninhabited-unstable-field.rs:24:9
3+
|
4+
LL | Foo { .. } => {}
5+
| ^^^^^^^^^^------
6+
| |
7+
| matches no values because `Foo<Void>` is uninhabited
8+
| help: remove the match arm
9+
|
10+
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
11+
note: the lint level is defined here
12+
--> $DIR/uninhabited-unstable-field.rs:9:9
13+
|
14+
LL | #![deny(unreachable_patterns)]
15+
| ^^^^^^^^^^^^^^^^^^^^
16+
17+
error: unreachable pattern
18+
--> $DIR/uninhabited-unstable-field.rs:31:9
19+
|
20+
LL | _ => {}
21+
| ^------
22+
| |
23+
| matches no values because `Foo<Void>` is uninhabited
24+
| help: remove the match arm
25+
|
26+
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
27+
28+
error: unreachable pattern
29+
--> $DIR/uninhabited-unstable-field.rs:41:9
30+
|
31+
LL | MyCoroutineState::Complete(_) => {}
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------
33+
| |
34+
| matches no values because `!` is uninhabited
35+
| help: remove the match arm
36+
|
37+
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
38+
39+
error: aborting due to 3 previous errors
40+

0 commit comments

Comments
 (0)