Skip to content

Commit 89fb42a

Browse files
committed
Do not normalize field types in elaborate_drops.
1 parent 754f6d4 commit 89fb42a

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ where
274274
let tcx = self.tcx();
275275

276276
assert_eq!(self.elaborator.param_env().reveal(), Reveal::All);
277-
let field_ty =
278-
tcx.normalize_erasing_regions(self.elaborator.param_env(), f.ty(tcx, substs));
277+
let field_ty = tcx.erase_regions(f.ty(tcx, substs));
279278
(tcx.mk_place_field(base_place, field, field_ty), subpath)
280279
})
281280
.collect()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- // MIR for `bar` before Inline
2+
+ // MIR for `bar` after Inline
3+
4+
fn bar(_1: *mut S<T>) -> () {
5+
debug p => _1; // in scope 0 at $DIR/issue_106444.rs:+0:28: +0:29
6+
let mut _0: (); // return place in scope 0 at $DIR/issue_106444.rs:+0:42: +0:42
7+
let _2: (); // in scope 0 at $DIR/issue_106444.rs:+2:14: +2:41
8+
let mut _3: *mut S<T>; // in scope 0 at $DIR/issue_106444.rs:+2:39: +2:40
9+
scope 1 {
10+
+ scope 2 (inlined std::ptr::drop_in_place::<S<T>> - shim(Some(S<T>))) { // at $DIR/issue_106444.rs:16:14: 16:41
11+
+ }
12+
}
13+
14+
bb0: {
15+
StorageLive(_2); // scope 0 at $DIR/issue_106444.rs:+2:5: +2:43
16+
StorageLive(_3); // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
17+
_3 = _1; // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
18+
- _2 = std::ptr::drop_in_place::<S<T>>(move _3) -> bb1; // scope 1 at $DIR/issue_106444.rs:+2:14: +2:41
19+
- // mir::Constant
20+
- // + span: $DIR/issue_106444.rs:16:14: 16:38
21+
- // + literal: Const { ty: unsafe fn(*mut S<T>) {std::ptr::drop_in_place::<S<T>>}, val: Value(<ZST>) }
22+
+ drop(((*_3).0: U)) -> bb1; // scope 2 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
23+
}
24+
25+
bb1: {
26+
StorageDead(_3); // scope 1 at $DIR/issue_106444.rs:+2:40: +2:41
27+
StorageDead(_2); // scope 0 at $DIR/issue_106444.rs:+2:43: +2:44
28+
_0 = const (); // scope 0 at $DIR/issue_106444.rs:+0:42: +3:2
29+
return; // scope 0 at $DIR/issue_106444.rs:+3:2: +3:2
30+
}
31+
}
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- // MIR for `foo` before Inline
2+
+ // MIR for `foo` after Inline
3+
4+
fn foo(_1: *mut S<T>) -> () {
5+
debug p => _1; // in scope 0 at $DIR/issue_106444.rs:+0:18: +0:19
6+
let mut _0: (); // return place in scope 0 at $DIR/issue_106444.rs:+0:32: +0:32
7+
let _2: (); // in scope 0 at $DIR/issue_106444.rs:+2:14: +2:41
8+
let mut _3: *mut S<T>; // in scope 0 at $DIR/issue_106444.rs:+2:39: +2:40
9+
scope 1 {
10+
+ scope 2 (inlined std::ptr::drop_in_place::<S<T>> - shim(Some(S<T>))) { // at $DIR/issue_106444.rs:11:14: 11:41
11+
+ }
12+
}
13+
14+
bb0: {
15+
StorageLive(_2); // scope 0 at $DIR/issue_106444.rs:+2:5: +2:43
16+
StorageLive(_3); // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
17+
_3 = _1; // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
18+
- _2 = std::ptr::drop_in_place::<S<T>>(move _3) -> bb1; // scope 1 at $DIR/issue_106444.rs:+2:14: +2:41
19+
- // mir::Constant
20+
- // + span: $DIR/issue_106444.rs:11:14: 11:38
21+
- // + literal: Const { ty: unsafe fn(*mut S<T>) {std::ptr::drop_in_place::<S<T>>}, val: Value(<ZST>) }
22+
+ drop(((*_3).0: <T as A>::B)) -> bb1; // scope 2 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
23+
}
24+
25+
bb1: {
26+
StorageDead(_3); // scope 1 at $DIR/issue_106444.rs:+2:40: +2:41
27+
StorageDead(_2); // scope 0 at $DIR/issue_106444.rs:+2:43: +2:44
28+
_0 = const (); // scope 0 at $DIR/issue_106444.rs:+0:32: +3:2
29+
return; // scope 0 at $DIR/issue_106444.rs:+3:2: +3:2
30+
}
31+
}
32+

tests/mir-opt/inline/issue_106444.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![crate_type = "lib"]
2+
3+
pub trait A {
4+
type B;
5+
}
6+
7+
pub struct S<T: A>(T::B);
8+
9+
pub fn foo<T: A>(p: *mut S<T>) {
10+
// Verify that we do not ICE when elaborating `Drop(*p)`.
11+
unsafe { core::ptr::drop_in_place(p) };
12+
}
13+
14+
pub fn bar<U, T: A<B = U>>(p: *mut S<T>) {
15+
// Verify that we use the correct type for `(*p).0` when elaborating `Drop(*p)`.
16+
unsafe { core::ptr::drop_in_place(p) };
17+
}
18+
19+
// EMIT_MIR issue_106444.foo.Inline.diff
20+
// EMIT_MIR issue_106444.bar.Inline.diff

0 commit comments

Comments
 (0)