Skip to content

Commit a1e7d38

Browse files
committed
Unconditionally run RevealAll pass and run it earlier
1 parent 1779252 commit a1e7d38

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

Diff for: compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
480480
let passes: &[&dyn MirPass<'tcx>] = &[
481481
// These next passes must be executed together
482482
&add_call_guards::CriticalCallEdges,
483+
&reveal_all::RevealAll, // has to be done before drop elaboration, since we need to drop opaque types, too.
483484
&elaborate_drops::ElaborateDrops,
484485
// This will remove extraneous landing pads which are no longer
485486
// necessary as well as well as forcing any call in a non-unwinding
@@ -526,7 +527,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
526527
body,
527528
&[
528529
&check_alignment::CheckAlignment,
529-
&reveal_all::RevealAll, // has to be done before inlining, since inlined code is in RevealAll mode.
530530
&lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first
531531
&unreachable_prop::UnreachablePropagation,
532532
&uninhabited_enum_branching::UninhabitedEnumBranching,

Diff for: compiler/rustc_mir_transform/src/reveal_all.rs

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
88
pub struct RevealAll;
99

1010
impl<'tcx> MirPass<'tcx> for RevealAll {
11-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
12-
sess.mir_opt_level() >= 3 || super::inline::Inline.is_enabled(sess)
13-
}
14-
1511
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1612
// Do not apply this transformation to generators.
1713
if body.generator.is_some() {

Diff for: tests/ui/polymorphization/generators.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ where
3232

3333
#[rustc_polymorphize_error]
3434
pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
35+
//~^ ERROR item has unused generic parameters
3536
|| {
3637
//~^ ERROR item has unused generic parameters
3738
yield 1;
@@ -57,6 +58,7 @@ pub fn used_type_in_return<R: Default>() -> impl Generator<(), Yield = u32, Retu
5758

5859
#[rustc_polymorphize_error]
5960
pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
61+
//~^ ERROR item has unused generic parameters
6062
|| {
6163
//~^ ERROR item has unused generic parameters
6264
yield 1;

Diff for: tests/ui/polymorphization/generators.stderr

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,34 @@ LL | #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
88
= note: `#[warn(incomplete_features)]` on by default
99

1010
error: item has unused generic parameters
11-
--> $DIR/generators.rs:35:5
11+
--> $DIR/generators.rs:36:5
1212
|
1313
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
1414
| - generic parameter `T` is unused
15+
LL |
1516
LL | || {
1617
| ^^
1718

1819
error: item has unused generic parameters
19-
--> $DIR/generators.rs:60:5
20+
--> $DIR/generators.rs:34:8
21+
|
22+
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
23+
| ^^^^^^^^^^^ - generic parameter `T` is unused
24+
25+
error: item has unused generic parameters
26+
--> $DIR/generators.rs:62:5
2027
|
2128
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
2229
| ------------ generic parameter `T` is unused
30+
LL |
2331
LL | || {
2432
| ^^
2533

26-
error: aborting due to 2 previous errors; 1 warning emitted
34+
error: item has unused generic parameters
35+
--> $DIR/generators.rs:60:8
36+
|
37+
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
38+
| ^^^^^^^^^^^^ ------------ generic parameter `T` is unused
39+
40+
error: aborting due to 4 previous errors; 1 warning emitted
2741

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// build-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
pub struct Foo {
6+
/// This type must have nontrivial drop glue
7+
field: String,
8+
}
9+
10+
pub type Tait = impl Sized;
11+
12+
pub fn ice_cold(beverage: Tait) {
13+
// Must destructure at least one field of `Foo`
14+
let Foo { field } = beverage;
15+
_ = field;
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)