Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not normalize field types in elaborate_drops. #106905

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_mir_dataflow/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ where
let tcx = self.tcx();

assert_eq!(self.elaborator.param_env().reveal(), Reveal::All);
let field_ty =
tcx.normalize_erasing_regions(self.elaborator.param_env(), f.ty(tcx, substs));
Comment on lines -277 to -278
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why the normalize was here in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. The call to normalize dates back to 2016.

let field_ty = tcx.erase_regions(f.ty(tcx, substs));
(tcx.mk_place_field(base_place, field, field_ty), subpath)
})
.collect()
Expand Down
32 changes: 32 additions & 0 deletions tests/mir-opt/inline/issue_106444.bar.Inline.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- // MIR for `bar` before Inline
+ // MIR for `bar` after Inline

fn bar(_1: *mut S<T>) -> () {
debug p => _1; // in scope 0 at $DIR/issue_106444.rs:+0:28: +0:29
let mut _0: (); // return place in scope 0 at $DIR/issue_106444.rs:+0:42: +0:42
let _2: (); // in scope 0 at $DIR/issue_106444.rs:+2:14: +2:41
let mut _3: *mut S<T>; // in scope 0 at $DIR/issue_106444.rs:+2:39: +2:40
scope 1 {
+ scope 2 (inlined std::ptr::drop_in_place::<S<T>> - shim(Some(S<T>))) { // at $DIR/issue_106444.rs:16:14: 16:41
+ }
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/issue_106444.rs:+2:5: +2:43
StorageLive(_3); // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
_3 = _1; // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
- _2 = std::ptr::drop_in_place::<S<T>>(move _3) -> bb1; // scope 1 at $DIR/issue_106444.rs:+2:14: +2:41
- // mir::Constant
- // + span: $DIR/issue_106444.rs:16:14: 16:38
- // + literal: Const { ty: unsafe fn(*mut S<T>) {std::ptr::drop_in_place::<S<T>>}, val: Value(<ZST>) }
+ drop(((*_3).0: U)) -> bb1; // scope 2 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
}

bb1: {
StorageDead(_3); // scope 1 at $DIR/issue_106444.rs:+2:40: +2:41
StorageDead(_2); // scope 0 at $DIR/issue_106444.rs:+2:43: +2:44
_0 = const (); // scope 0 at $DIR/issue_106444.rs:+0:42: +3:2
return; // scope 0 at $DIR/issue_106444.rs:+3:2: +3:2
}
}

32 changes: 32 additions & 0 deletions tests/mir-opt/inline/issue_106444.foo.Inline.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- // MIR for `foo` before Inline
+ // MIR for `foo` after Inline

fn foo(_1: *mut S<T>) -> () {
debug p => _1; // in scope 0 at $DIR/issue_106444.rs:+0:18: +0:19
let mut _0: (); // return place in scope 0 at $DIR/issue_106444.rs:+0:32: +0:32
let _2: (); // in scope 0 at $DIR/issue_106444.rs:+2:14: +2:41
let mut _3: *mut S<T>; // in scope 0 at $DIR/issue_106444.rs:+2:39: +2:40
scope 1 {
+ scope 2 (inlined std::ptr::drop_in_place::<S<T>> - shim(Some(S<T>))) { // at $DIR/issue_106444.rs:11:14: 11:41
+ }
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/issue_106444.rs:+2:5: +2:43
StorageLive(_3); // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
_3 = _1; // scope 1 at $DIR/issue_106444.rs:+2:39: +2:40
- _2 = std::ptr::drop_in_place::<S<T>>(move _3) -> bb1; // scope 1 at $DIR/issue_106444.rs:+2:14: +2:41
- // mir::Constant
- // + span: $DIR/issue_106444.rs:11:14: 11:38
- // + literal: Const { ty: unsafe fn(*mut S<T>) {std::ptr::drop_in_place::<S<T>>}, val: Value(<ZST>) }
+ drop(((*_3).0: <T as A>::B)) -> bb1; // scope 2 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
}

bb1: {
StorageDead(_3); // scope 1 at $DIR/issue_106444.rs:+2:40: +2:41
StorageDead(_2); // scope 0 at $DIR/issue_106444.rs:+2:43: +2:44
_0 = const (); // scope 0 at $DIR/issue_106444.rs:+0:32: +3:2
return; // scope 0 at $DIR/issue_106444.rs:+3:2: +3:2
}
}

20 changes: 20 additions & 0 deletions tests/mir-opt/inline/issue_106444.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![crate_type = "lib"]

pub trait A {
type B;
}

pub struct S<T: A>(T::B);

pub fn foo<T: A>(p: *mut S<T>) {
// Verify that we do not ICE when elaborating `Drop(*p)`.
unsafe { core::ptr::drop_in_place(p) };
}

pub fn bar<U, T: A<B = U>>(p: *mut S<T>) {
// Verify that we use the correct type for `(*p).0` when elaborating `Drop(*p)`.
unsafe { core::ptr::drop_in_place(p) };
}

// EMIT_MIR issue_106444.foo.Inline.diff
// EMIT_MIR issue_106444.bar.Inline.diff