Skip to content

Commit e1afa51

Browse files
committed
Fix Mir visitor macro to ensure it calls the proper method to invalidate the predecessors cache
1 parent 2b31456 commit e1afa51

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/librustc/mir/visit.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -789,19 +789,31 @@ macro_rules! make_mir_visitor {
789789
}
790790

791791
// Convenience methods
792-
793-
fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {
794-
let basic_block = & $($mutability)? body[location.block];
795-
if basic_block.statements.len() == location.statement_index {
796-
// TODO(nashenas88) how to ensure we clear the cache only in the mutable case...
797-
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
798-
self.visit_terminator(terminator, location)
799-
}
800-
} else {
801-
let statement = & $($mutability)?
802-
basic_block.statements[location.statement_index];
803-
self.visit_statement(statement, location)
792+
make_mir_visitor!{@make_visit_location, $($mutability)?}
793+
}
794+
};
795+
(@make_visit_location, mut) => {
796+
fn visit_location(&mut self, body: &mut Body<'tcx>, location: Location) {
797+
if body[location.block].statements.len() == location.statement_index {
798+
if let Some(ref mut terminator) = body.basic_block_terminator_opt_mut(location.block) {
799+
self.visit_terminator(terminator, location)
800+
}
801+
} else {
802+
let statement = &mut body[location.block].statements[location.statement_index];
803+
self.visit_statement(statement, location)
804+
}
805+
}
806+
};
807+
(@make_visit_location, ) => {
808+
fn visit_location(&mut self, body: &Body<'tcx>, location: Location) {
809+
let basic_block = &body[location.block];
810+
if basic_block.statements.len() == location.statement_index {
811+
if let Some(ref terminator) = basic_block.terminator_opt() {
812+
self.visit_terminator(terminator, location)
804813
}
814+
} else {
815+
let statement = &basic_block.statements[location.statement_index];
816+
self.visit_statement(statement, location)
805817
}
806818
}
807819
}

0 commit comments

Comments
 (0)