@@ -14,6 +14,7 @@ use rustc::mir::{Local, Location, Place};
1414use rustc_data_structures:: fx:: FxHashSet ;
1515
1616use borrow_check:: MirBorrowckCtxt ;
17+ use util:: collect_writes:: is_place_assignment;
1718
1819impl < ' 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}
0 commit comments