From 89fb42ab748138fc73388dd978d45d0bfa74be43 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 15 Jan 2023 09:57:27 +0000 Subject: [PATCH] Do not normalize field types in elaborate_drops. --- .../rustc_mir_dataflow/src/elaborate_drops.rs | 3 +- .../inline/issue_106444.bar.Inline.diff | 32 +++++++++++++++++++ .../inline/issue_106444.foo.Inline.diff | 32 +++++++++++++++++++ tests/mir-opt/inline/issue_106444.rs | 20 ++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/mir-opt/inline/issue_106444.bar.Inline.diff create mode 100644 tests/mir-opt/inline/issue_106444.foo.Inline.diff create mode 100644 tests/mir-opt/inline/issue_106444.rs diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index 7836ae2e7b76f..f23c89e7c3f51 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -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)); + let field_ty = tcx.erase_regions(f.ty(tcx, substs)); (tcx.mk_place_field(base_place, field, field_ty), subpath) }) .collect() diff --git a/tests/mir-opt/inline/issue_106444.bar.Inline.diff b/tests/mir-opt/inline/issue_106444.bar.Inline.diff new file mode 100644 index 0000000000000..804758b3eda89 --- /dev/null +++ b/tests/mir-opt/inline/issue_106444.bar.Inline.diff @@ -0,0 +1,32 @@ +- // MIR for `bar` before Inline ++ // MIR for `bar` after Inline + + fn bar(_1: *mut S) -> () { + 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; // in scope 0 at $DIR/issue_106444.rs:+2:39: +2:40 + scope 1 { ++ scope 2 (inlined std::ptr::drop_in_place::> - shim(Some(S))) { // 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::>(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) {std::ptr::drop_in_place::>}, val: Value() } ++ 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 + } + } + diff --git a/tests/mir-opt/inline/issue_106444.foo.Inline.diff b/tests/mir-opt/inline/issue_106444.foo.Inline.diff new file mode 100644 index 0000000000000..c1f0a6c7d4de4 --- /dev/null +++ b/tests/mir-opt/inline/issue_106444.foo.Inline.diff @@ -0,0 +1,32 @@ +- // MIR for `foo` before Inline ++ // MIR for `foo` after Inline + + fn foo(_1: *mut S) -> () { + 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; // in scope 0 at $DIR/issue_106444.rs:+2:39: +2:40 + scope 1 { ++ scope 2 (inlined std::ptr::drop_in_place::> - shim(Some(S))) { // 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::>(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) {std::ptr::drop_in_place::>}, val: Value() } ++ drop(((*_3).0: ::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 + } + } + diff --git a/tests/mir-opt/inline/issue_106444.rs b/tests/mir-opt/inline/issue_106444.rs new file mode 100644 index 0000000000000..e05ec10b2a08a --- /dev/null +++ b/tests/mir-opt/inline/issue_106444.rs @@ -0,0 +1,20 @@ +#![crate_type = "lib"] + +pub trait A { + type B; +} + +pub struct S(T::B); + +pub fn foo(p: *mut S) { + // Verify that we do not ICE when elaborating `Drop(*p)`. + unsafe { core::ptr::drop_in_place(p) }; +} + +pub fn bar>(p: *mut S) { + // 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