Skip to content

Commit 7a266a6

Browse files
committed
minor changes
1 parent bfc9b76 commit 7a266a6

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15361536
is_local_mutation_allowed: LocalMutationIsAllowed,
15371537
) -> bool {
15381538
debug!(
1539+
<<<<<<< HEAD
15391540
"check_access_permissions({:?}, {:?}, {:?})",
15401541
place, kind, is_local_mutation_allowed
1542+
=======
1543+
" ({:?}, {:?}, {:?})",
1544+
place,
1545+
kind,
1546+
is_local_mutation_allowed
1547+
>>>>>>> minor changes
15411548
);
15421549
let mut error_reported = false;
15431550
match kind {
@@ -1573,13 +1580,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15731580
if let Err(place_err) = self.is_mutable(place, is_local_mutation_allowed) {
15741581
error_reported = true;
15751582

1576-
match *place{
1577-
Place::Local(local) => {let locations = self.mir.find_assignments(local);
1578-
1579-
for n in &locations{
1580-
debug!("locations ={:?}", n);}
1583+
let err_help = match *place {
1584+
Place::Local(local) => {
1585+
let locations = self.mir.find_assignments(local);
1586+
Some((self.mir.source_info(locations[0]).span, "consider changing this to be a mutable reference: `&mut `"))
15811587
}
1582-
_ => {}}
1588+
_ => {
1589+
None
1590+
}
1591+
};
15831592

15841593
let item_msg = if error_reported{
15851594
if let Some(name) = self.describe_place(place_err) {
@@ -1602,6 +1611,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16021611
if place != place_err {
16031612
err.span_label(span, "cannot assign through `&`-reference");
16041613
}
1614+
1615+
if !err_help.is_none(){
1616+
let (err_help_span, err_help_stmt) = err_help.unwrap();
1617+
err.span_help(err_help_span, err_help_stmt);}
16051618
err.emit();
16061619
}
16071620
}

src/librustc_mir/util/collect_writes.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
2626
self.locations.push(location);
2727
}
2828
PlaceContext::AsmOutput | PlaceContext::Drop| PlaceContext::Inspect |
29-
PlaceContext::Borrow{..}| PlaceContext::Projection(..)| PlaceContext::Copy|
29+
PlaceContext::Borrow{..}| PlaceContext::Projection(..)| PlaceContext::Copy|
3030
PlaceContext::Move| PlaceContext::StorageLive| PlaceContext::StorageDead|
3131
PlaceContext::Validate => {
32+
// self.super_local(local)
3233
}
3334
}
34-
35-
Visitor::visit_local(self,local,place_context,location)
3635
}
36+
37+
// fn super_local()
3738
}
3839

3940
crate trait FindAssignments {
40-
fn find_assignments(&self, local: Local) -> Vec<Location>;
41+
fn find_assignments(&self, local: Local) -> Vec<Location>;
4142
}
4243

4344
impl<'tcx> FindAssignments for Mir<'tcx>{

0 commit comments

Comments
 (0)