Skip to content

Commit ad0b7ed

Browse files
committed
Auto merge of rust-lang#116254 - WaffleLapkin:nicen-traversal, r=cjgillot
Assorted improvements for `rustc_middle::mir::traversal` r? `@cjgillot` I'm not _entirely_ sure about all changes, although I do like all of them. If you'd like I can drop some commits. Best reviewed on a commit-by-commit basis, I think, since they are fairly isolated.
2 parents 1a82ca0 + a4d11d9 commit ad0b7ed

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

clippy_utils/src/mir/mod.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,26 @@ pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) -
3030
locals.len()
3131
];
3232

33-
traversal::ReversePostorder::new(mir, location.block).try_fold(init, |usage, (tbb, tdata)| {
34-
// Give up on loops
35-
if tdata.terminator().successors().any(|s| s == location.block) {
36-
return None;
37-
}
33+
traversal::Postorder::new(&mir.basic_blocks, location.block)
34+
.collect::<Vec<_>>()
35+
.into_iter()
36+
.rev()
37+
.try_fold(init, |usage, tbb| {
38+
let tdata = &mir.basic_blocks[tbb];
39+
40+
// Give up on loops
41+
if tdata.terminator().successors().any(|s| s == location.block) {
42+
return None;
43+
}
3844

39-
let mut v = V {
40-
locals,
41-
location,
42-
results: usage,
43-
};
44-
v.visit_basic_block_data(tbb, tdata);
45-
Some(v.results)
46-
})
45+
let mut v = V {
46+
locals,
47+
location,
48+
results: usage,
49+
};
50+
v.visit_basic_block_data(tbb, tdata);
51+
Some(v.results)
52+
})
4753
}
4854

4955
struct V<'a> {

0 commit comments

Comments
 (0)