Move inner items outside
This commit is contained in:
parent
cd5d7201ad
commit
682de94e31
@ -858,15 +858,26 @@ fn find_candidates<'a, 'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
) -> Vec<CandidateAssignment<'tcx>> {
|
||||
struct FindAssignments<'a, 'tcx> {
|
||||
let mut visitor = FindAssignments {
|
||||
tcx,
|
||||
body,
|
||||
candidates: Vec::new(),
|
||||
ever_borrowed_locals: ever_borrowed_locals(body),
|
||||
locals_used_as_array_index: locals_used_as_array_index(body),
|
||||
};
|
||||
visitor.visit_body(body);
|
||||
visitor.candidates
|
||||
}
|
||||
|
||||
struct FindAssignments<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
candidates: Vec<CandidateAssignment<'tcx>>,
|
||||
ever_borrowed_locals: BitSet<Local>,
|
||||
locals_used_as_array_index: BitSet<Local>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
|
||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||
if let StatementKind::Assign(box (
|
||||
dest,
|
||||
@ -939,17 +950,6 @@ fn find_candidates<'a, 'tcx>(
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut visitor = FindAssignments {
|
||||
tcx,
|
||||
body,
|
||||
candidates: Vec::new(),
|
||||
ever_borrowed_locals: ever_borrowed_locals(body),
|
||||
locals_used_as_array_index: locals_used_as_array_index(body),
|
||||
};
|
||||
visitor.visit_body(body);
|
||||
visitor.candidates
|
||||
}
|
||||
|
||||
/// Some locals are part of the function's interface and can not be removed.
|
||||
@ -965,11 +965,16 @@ fn is_local_required(local: Local, body: &Body<'_>) -> bool {
|
||||
|
||||
/// Walks MIR to find all locals that have their address taken anywhere.
|
||||
fn ever_borrowed_locals(body: &Body<'_>) -> BitSet<Local> {
|
||||
struct BorrowCollector {
|
||||
locals: BitSet<Local>,
|
||||
}
|
||||
let mut visitor = BorrowCollector { locals: BitSet::new_empty(body.local_decls.len()) };
|
||||
visitor.visit_body(body);
|
||||
visitor.locals
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for BorrowCollector {
|
||||
struct BorrowCollector {
|
||||
locals: BitSet<Local>,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for BorrowCollector {
|
||||
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
|
||||
self.super_rvalue(rvalue, location);
|
||||
|
||||
@ -1018,11 +1023,6 @@ fn ever_borrowed_locals(body: &Body<'_>) -> BitSet<Local> {
|
||||
| TerminatorKind::InlineAsm { .. } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut visitor = BorrowCollector { locals: BitSet::new_empty(body.local_decls.len()) };
|
||||
visitor.visit_body(body);
|
||||
visitor.locals
|
||||
}
|
||||
|
||||
/// `PlaceElem::Index` only stores a `Local`, so we can't replace that with a full `Place`.
|
||||
@ -1030,11 +1030,16 @@ fn ever_borrowed_locals(body: &Body<'_>) -> BitSet<Local> {
|
||||
/// Collect locals used as indices so we don't generate candidates that are impossible to apply
|
||||
/// later.
|
||||
fn locals_used_as_array_index(body: &Body<'_>) -> BitSet<Local> {
|
||||
struct IndexCollector {
|
||||
locals: BitSet<Local>,
|
||||
}
|
||||
let mut visitor = IndexCollector { locals: BitSet::new_empty(body.local_decls.len()) };
|
||||
visitor.visit_body(body);
|
||||
visitor.locals
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for IndexCollector {
|
||||
struct IndexCollector {
|
||||
locals: BitSet<Local>,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for IndexCollector {
|
||||
fn visit_projection_elem(
|
||||
&mut self,
|
||||
local: Local,
|
||||
@ -1048,9 +1053,4 @@ fn locals_used_as_array_index(body: &Body<'_>) -> BitSet<Local> {
|
||||
}
|
||||
self.super_projection_elem(local, proj_base, elem, context, location);
|
||||
}
|
||||
}
|
||||
|
||||
let mut visitor = IndexCollector { locals: BitSet::new_empty(body.local_decls.len()) };
|
||||
visitor.visit_body(body);
|
||||
visitor.locals
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user