Skip to content

Commit f00be8b

Browse files
committed
Recurse into statement before applying its effect.
1 parent d97a7ce commit f00be8b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
829829

830830
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
831831
trace!("visit_statement: {:?}", statement);
832+
833+
// Recurse into statement before applying the assignment.
834+
self.super_statement(statement, location);
835+
832836
match statement.kind {
833837
StatementKind::Assign(box (place, ref mut rval)) => {
834838
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
@@ -905,8 +909,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
905909
}
906910
_ => {}
907911
}
908-
909-
self.super_statement(statement, location);
910912
}
911913

912914
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {

compiler/rustc_mir_transform/src/const_prop_lint.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
511511
trace!("visit_statement: {:?}", statement);
512512
let source_info = statement.source_info;
513513
self.source_info = Some(source_info);
514+
515+
// Recurse into statement before applying the assignment.
516+
self.super_statement(statement, location);
517+
514518
match statement.kind {
515519
StatementKind::Assign(box (place, ref rval)) => {
516520
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
@@ -576,8 +580,6 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
576580
}
577581
_ => {}
578582
}
579-
580-
self.super_statement(statement, location);
581583
}
582584

583585
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {

tests/ui/consts/const-err-late.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ note: erroneous constant used
1010
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
1111
| ^^^^^^^^^^^^^
1212

13-
note: erroneous constant used
14-
--> $DIR/const-err-late.rs:19:16
15-
|
16-
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
17-
| ^^^^^^^^^^^^^
18-
1913
error[E0080]: evaluation of `S::<u32>::FOO` failed
2014
--> $DIR/const-err-late.rs:13:21
2115
|
@@ -34,6 +28,12 @@ note: erroneous constant used
3428
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
3529
| ^^^^^^^^^^^^^
3630

31+
note: erroneous constant used
32+
--> $DIR/const-err-late.rs:19:16
33+
|
34+
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
35+
| ^^^^^^^^^^^^^
36+
3737
error: aborting due to 2 previous errors
3838

3939
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)