Skip to content

Commit 1fb25fb

Browse files
committed
reduce nested loops in the code
1 parent 12d1415 commit 1fb25fb

File tree

2 files changed

+61
-29
lines changed

2 files changed

+61
-29
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,38 +1565,70 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15651565
error_reported = true;
15661566

15671567
let mut err_info = None;
1568+
15681569
match *place_err {
1569-
Place::Projection(ref proj) => {
1570-
match proj.elem {
1571-
ProjectionElem::Deref => {
1572-
match proj.base {
1573-
Place::Local(local) => {
1574-
let locations = self.mir.find_assignments(local);
1575-
if locations.len() > 0 {
1576-
let item_msg = if error_reported {
1577-
match self.specialized_description(&proj.base){
1578-
Some(msg) => msg,
1579-
None => self.get_main_error_message(place)
1580-
}
1581-
} else {
1582-
self.get_main_error_message(place)
1583-
};
1584-
err_info = Some((
1585-
self.mir.source_info(locations[0]).span,
1586-
"consider changing this to be a \
1587-
mutable reference: `&mut`", item_msg,
1588-
"cannot assign through `&`-reference"));
1589-
}
1570+
1571+
Place::Projection(box Projection {
1572+
ref base, elem:ProjectionElem::Deref}) => {
1573+
1574+
match *base {
1575+
Place::Local(local) => {
1576+
let locations = self.mir.find_assignments(local);
1577+
if locations.len() > 0 {
1578+
let item_msg = if error_reported {
1579+
match self.specialized_description(base){
1580+
Some(msg) => msg,
1581+
None => self.get_main_error_message(place)
1582+
}
1583+
} else {
1584+
self.get_main_error_message(place)
1585+
};
1586+
err_info = Some((
1587+
self.mir.source_info(locations[0]).span,
1588+
"consider changing this to be a \
1589+
mutable reference: `&mut`", item_msg,
1590+
"cannot assign through `&`-reference"));
15901591
}
1591-
_ => {},
1592-
}
1593-
}
1594-
_ => {}
1592+
},
1593+
_ => {},
15951594
}
1596-
}
1597-
_ => {}
1595+
},
1596+
_ => {},
15981597
}
15991598

1599+
1600+
// match *place_err {
1601+
// Place::Projection(ref proj) => {
1602+
// match proj.elem {
1603+
// ProjectionElem::Deref => {
1604+
// match proj.base {
1605+
// Place::Local(local) => {
1606+
// let locations = self.mir.find_assignments(local);
1607+
// if locations.len() > 0 {
1608+
// let item_msg = if error_reported {
1609+
// match self.specialized_description(base){
1610+
// Some(msg) => msg,
1611+
// None => self.get_main_error_message(place)
1612+
// }
1613+
// } else {
1614+
// self.get_main_error_message(place)
1615+
// };
1616+
// err_info = Some((
1617+
// self.mir.source_info(locations[0]).span,
1618+
// "consider changing this to be a \
1619+
// mutable reference: `&mut`", item_msg,
1620+
// "cannot assign through `&`-reference"));
1621+
// }
1622+
// }
1623+
// _ => {},
1624+
// }
1625+
// }
1626+
// _ => {}
1627+
// }
1628+
// }
1629+
// _ => {}
1630+
// }
1631+
16001632
if let Some((err_help_span, err_help_stmt, item_msg, sec_span)) = err_info {
16011633
let mut err = self.tcx.cannot_assign(span, &item_msg, Origin::Mir, true);
16021634
err.span_suggestion(err_help_span, err_help_stmt, format!(""));

src/librustc_mir/util/borrowck_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ pub trait BorrowckErrors<'cx>: Sized + Copy {
284284
self.cancel_if_wrong_origin(err, o)
285285
}
286286

287-
fn cannot_assign(&self, span: Span, desc: &str, o: Origin, is_reference:bool)
288-
-> DiagnosticBuilder
287+
fn cannot_assign(self, span: Span, desc: &str, o: Origin, is_reference: bool)
288+
-> DiagnosticBuilder<'cx>
289289
{
290290
let msg = if is_reference {
291291
"through"

0 commit comments

Comments
 (0)