Skip to content

Commit 63a4e72

Browse files
committed
Share code between gather_used_muts and find_assignments
1 parent 7154383 commit 63a4e72

File tree

2 files changed

+30
-42
lines changed

2 files changed

+30
-42
lines changed

src/librustc_mir/borrow_check/used_muts.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc::mir::{Local, Location, Place};
1414
use rustc_data_structures::fx::FxHashSet;
1515

1616
use borrow_check::MirBorrowckCtxt;
17+
use util::collect_writes::is_place_assignment;
1718

1819
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1920
/// Walks the MIR looking for assignments to a set of locals, as part of the unused mutable
@@ -45,31 +46,19 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
4546
return;
4647
}
4748

48-
match place_context {
49-
PlaceContext::Store | PlaceContext::Call => {
50-
// Propagate the Local assigned at this Location as a used mutable local variable
51-
for moi in &self.mbcx.move_data.loc_map[location] {
52-
let mpi = &self.mbcx.move_data.moves[*moi].path;
53-
let path = &self.mbcx.move_data.move_paths[*mpi];
54-
debug!(
55-
"assignment of {:?} to {:?}, adding {:?} to used mutable set",
56-
path.place, local, path.place
57-
);
58-
if let Place::Local(user_local) = path.place {
59-
self.mbcx.used_mut.insert(user_local);
60-
}
49+
if is_place_assignment(&place_context) {
50+
// Propagate the Local assigned at this Location as a used mutable local variable
51+
for moi in &self.mbcx.move_data.loc_map[location] {
52+
let mpi = &self.mbcx.move_data.moves[*moi].path;
53+
let path = &self.mbcx.move_data.move_paths[*mpi];
54+
debug!(
55+
"assignment of {:?} to {:?}, adding {:?} to used mutable set",
56+
path.place, local, path.place
57+
);
58+
if let Place::Local(user_local) = path.place {
59+
self.mbcx.used_mut.insert(user_local);
6160
}
6261
}
63-
PlaceContext::AsmOutput
64-
| PlaceContext::Drop
65-
| PlaceContext::Inspect
66-
| PlaceContext::Borrow { .. }
67-
| PlaceContext::Projection(..)
68-
| PlaceContext::Copy
69-
| PlaceContext::Move
70-
| PlaceContext::StorageLive
71-
| PlaceContext::StorageDead
72-
| PlaceContext::Validate => {}
7362
}
7463
}
7564
}

src/librustc_mir/util/collect_writes.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,24 @@ impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
4343
return;
4444
}
4545

46-
match place_context {
47-
PlaceContext::Store | PlaceContext::Call => {
48-
self.locations.push(location);
49-
}
50-
PlaceContext::AsmOutput |
51-
PlaceContext::Drop |
52-
PlaceContext::Inspect |
53-
PlaceContext::Borrow { .. } |
54-
PlaceContext::Projection(..) |
55-
PlaceContext::Copy |
56-
PlaceContext::Move |
57-
PlaceContext::StorageLive |
58-
PlaceContext::StorageDead |
59-
PlaceContext::Validate => {
60-
// TO-DO
61-
// self.super_local(local)
62-
}
46+
if is_place_assignment(&place_context) {
47+
self.locations.push(location);
6348
}
6449
}
65-
// TO-DO
66-
// fn super_local()
50+
}
51+
52+
/// Returns true if this place context represents an assignment statement
53+
crate fn is_place_assignment(place_context: &PlaceContext) -> bool {
54+
match *place_context {
55+
PlaceContext::Store | PlaceContext::Call | PlaceContext::AsmOutput => true,
56+
PlaceContext::Drop
57+
| PlaceContext::Inspect
58+
| PlaceContext::Borrow { .. }
59+
| PlaceContext::Projection(..)
60+
| PlaceContext::Copy
61+
| PlaceContext::Move
62+
| PlaceContext::StorageLive
63+
| PlaceContext::StorageDead
64+
| PlaceContext::Validate => false,
65+
}
6766
}

0 commit comments

Comments
 (0)