Skip to content

Commit 2724243

Browse files
committed
Reverse postorder instead of using reversed postorder
1 parent 0e0dc59 commit 2724243

File tree

1 file changed

+19
-13
lines changed
  • src/tools/clippy/clippy_utils/src/mir

1 file changed

+19
-13
lines changed

src/tools/clippy/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)