diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 6e590981357..334dd90d4ae 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -891,7 +891,8 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> { fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) { trace!("visit_statement: {:?}", statement); - // Recurse into statement before applying the assignment. + // We want to evaluate operands before any change to the assigned-to value, + // so we recurse first. self.super_statement(statement, location); match statement.kind { diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 28198781fd9..cbf29380ff2 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -556,7 +556,8 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> { let source_info = statement.source_info; self.source_info = Some(source_info); - // Recurse into statement before applying the assignment. + // We want to evaluate operands before any change to the assigned-to value, + // so we recurse first. self.super_statement(statement, location); match statement.kind {