Skip to content

Commit e3f388f

Browse files
committed
Auto merge of rust-lang#115759 - oli-obk:open_drop_from_non-ADT, r=<try>
Reveal opaque types before drop elaboration fixes rust-lang#113594 r? `@cjgillot` cc `@JakobDegen` This pass was introduced in rust-lang#110714 I moved it before drop elaboration (which only cares about the hidden types of things, not the opaque TAIT or RPIT type) and set it to run unconditionally (instead of depending on the optimization level and whether the inliner is active)
2 parents 68c2f5b + a1e7d38 commit e3f388f

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ where
194194
D: DropElaborator<'b, 'tcx>,
195195
'tcx: 'b,
196196
{
197+
#[instrument(level = "trace", skip(self), ret)]
197198
fn place_ty(&self, place: Place<'tcx>) -> Ty<'tcx> {
198199
place.ty(self.elaborator.body(), self.tcx()).ty
199200
}
@@ -220,11 +221,9 @@ where
220221
//
221222
// FIXME: I think we should just control the flags externally,
222223
// and then we do not need this machinery.
224+
#[instrument(level = "debug")]
223225
pub fn elaborate_drop(&mut self, bb: BasicBlock) {
224-
debug!("elaborate_drop({:?}, {:?})", bb, self);
225-
let style = self.elaborator.drop_style(self.path, DropFlagMode::Deep);
226-
debug!("elaborate_drop({:?}, {:?}): live - {:?}", bb, self, style);
227-
match style {
226+
match self.elaborator.drop_style(self.path, DropFlagMode::Deep) {
228227
DropStyle::Dead => {
229228
self.elaborator
230229
.patch()

compiler/rustc_mir_transform/src/elaborate_drops.rs

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, '_, 'tcx> {
170170
self.ctxt.param_env()
171171
}
172172

173+
#[instrument(level = "debug", skip(self), ret)]
173174
fn drop_style(&self, path: Self::Path, mode: DropFlagMode) -> DropStyle {
174175
let ((maybe_live, maybe_dead), multipart) = match mode {
175176
DropFlagMode::Shallow => (self.ctxt.init_data.maybe_live_dead(path), false),

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,

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() {

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;

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)