Skip to content

Commit f60788b

Browse files
committed
update visit_local for FindLocalAssignmentVisitor
1 parent 308e30e commit f60788b

File tree

1 file changed

+29
-44
lines changed
  • src/librustc_mir/borrow_check

1 file changed

+29
-44
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,33 @@ mod prefixes;
5757
use std::borrow::Cow;
5858

5959
struct FindLocalAssignmentVisitor {
60-
from: Local,
61-
loc: Vec<Location>,
60+
needle: Local,
61+
locations: Vec<Location>,
62+
placectxt: PlaceContext,
63+
location: Location,
6264
}
6365

6466
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
6567
fn visit_local(&mut self,
66-
local: &mut Local,
67-
_: PlaceContext<'tcx>,
68-
_: Location) {
69-
Visitor::visit_local(local,)
68+
local: &Local,
69+
place_context: PlaceContext<'tcx>,
70+
location: Location) {
71+
if self.needle != *local {
72+
return;
73+
}
74+
75+
match place_context {
76+
PlaceContext::Store | PlaceContext::Call => {
77+
self.locations.push(location);
78+
}
79+
PlaceContext::AsmOutput | PlaceContext::Drop| PlaceContext::Inspect |
80+
PlaceContext::Borrow| PlaceContext::Projection| PlaceContext::Copy|
81+
PlaceContext::Move| PlaceContext::StorageLive| PlaceContext::StorageDead|
82+
PlaceContext::Validate => {
83+
}
84+
}
85+
86+
Visitor::visit_local(local,place_context,location)
7087
}
7188
}
7289

@@ -1570,41 +1587,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15701587
None => "immutable item".to_owned(),
15711588
};
15721589

1573-
// let item_msg = match place{
1574-
// Place::Projection(ref proj) => {
1575-
// let Projection { ref base, ref elem } = **proj;
1576-
// match *elem {
1577-
// ProjectionElem::Deref => {
1578-
// if let Err(place_err) = self.is_mutable(place, is_local_mutation_allowed) {
1579-
// debug!("place_err = {:?} and base={:?}", place_err, base);
1580-
// format!("`&`-reference {:?}", place_err)
1581-
1582-
1583-
// }else{
1584-
// match self.describe_place(place) {
1585-
// Some(name) => format!("immutable item `{}`", name),
1586-
// None => "immutable item".to_owned(),
1587-
// }
1588-
// }
1589-
// }
1590-
// _ => {
1591-
// match self.describe_place(place) {
1592-
// Some(name) => format!("immutable item `{}`", name),
1593-
// None => "immutable item".to_owned(),
1594-
// }
1595-
1596-
// }
1597-
// }
1598-
// },
1599-
1600-
// _=> {
1601-
// match self.describe_place(place) {
1602-
// Some(name) => format!("immutable item `{}`", name),
1603-
// None => "immutable item".to_owned(),
1604-
// }
1605-
// }
1606-
// };
1607-
1590+
// call find_assignments() here
16081591
let mut err = self.tcx
16091592
.cannot_borrow_path_as_mutable(span, &item_msg, Origin::Mir);
16101593
err.span_label(span, "cannot borrow as mutable");
@@ -2286,10 +2269,12 @@ impl ContextKind {
22862269
}
22872270
}
22882271

2289-
impl Mir {
2290-
fn find_assignments(&self, local: Local) -> Vec<Location>
2272+
impl Mir {
2273+
fn find_assignments(&self, local: Local, place_context:PlaceContext, location:Location) -> Vec<Location>
22912274
{
2292-
2275+
let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![], location:location, place_context: };
2276+
visitor.visit_mir(self);
2277+
visitor.locations
22932278
}
22942279
}
22952280

0 commit comments

Comments
 (0)