diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 9a16003bdc9..b96125de95e 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -439,6 +439,7 @@ fn check_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Option<()> { // FIXME we need to revisit this for #67176 if rvalue.has_param() { + trace!("skipping, has param"); return None; } if !rvalue @@ -707,7 +708,11 @@ fn visit_projection_elem( fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { self.super_assign(place, rvalue, location); - let Some(()) = self.check_rvalue(rvalue) else { return }; + let Some(()) = self.check_rvalue(rvalue) else { + trace!("rvalue check failed, removing const"); + Self::remove_const(&mut self.ecx, place.local); + return; + }; match self.ecx.machine.can_const_prop[place.local] { // Do nothing if the place is indirect. diff --git a/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff b/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff index 0f44c49bc4d..ad8318832d6 100644 --- a/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff +++ b/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff @@ -12,8 +12,7 @@ StorageLive(_1); _1 = const 0_usize; _1 = const _; -- _0 = _1; -+ _0 = const 0_usize; + _0 = _1; StorageDead(_1); return; }