Skip to content

Commit

Permalink
Auto merge of rust-lang#116254 - WaffleLapkin:nicen-traversal, r=cjgi…
Browse files Browse the repository at this point in the history
…llot

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.
  • Loading branch information
bors committed Sep 30, 2023
2 parents 1a82ca0 + a4d11d9 commit ad0b7ed
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions clippy_utils/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,26 @@ pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) -
locals.len()
];

traversal::ReversePostorder::new(mir, location.block).try_fold(init, |usage, (tbb, tdata)| {
// Give up on loops
if tdata.terminator().successors().any(|s| s == location.block) {
return None;
}
traversal::Postorder::new(&mir.basic_blocks, location.block)
.collect::<Vec<_>>()
.into_iter()
.rev()
.try_fold(init, |usage, tbb| {
let tdata = &mir.basic_blocks[tbb];

// Give up on loops
if tdata.terminator().successors().any(|s| s == location.block) {
return None;
}

let mut v = V {
locals,
location,
results: usage,
};
v.visit_basic_block_data(tbb, tdata);
Some(v.results)
})
let mut v = V {
locals,
location,
results: usage,
};
v.visit_basic_block_data(tbb, tdata);
Some(v.results)
})
}

struct V<'a> {
Expand Down

0 comments on commit ad0b7ed

Please sign in to comment.