From 1fb25fbbe30e81bdbc9b8b63b01603d7a6124209 Mon Sep 17 00:00:00 2001 From: gaurikholkar Date: Fri, 6 Apr 2018 20:00:21 +0530 Subject: [PATCH] reduce nested loops in the code --- src/librustc_mir/borrow_check/mod.rs | 86 ++++++++++++++++-------- src/librustc_mir/util/borrowck_errors.rs | 4 +- 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 636909d096e1..9f84e3469cdc 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1565,38 +1565,70 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { error_reported = true; let mut err_info = None; + match *place_err { - Place::Projection(ref proj) => { - match proj.elem { - ProjectionElem::Deref => { - match proj.base { - Place::Local(local) => { - let locations = self.mir.find_assignments(local); - if locations.len() > 0 { - let item_msg = if error_reported { - match self.specialized_description(&proj.base){ - Some(msg) => msg, - None => self.get_main_error_message(place) - } - } else { - self.get_main_error_message(place) - }; - err_info = Some(( - self.mir.source_info(locations[0]).span, - "consider changing this to be a \ - mutable reference: `&mut`", item_msg, - "cannot assign through `&`-reference")); - } + + Place::Projection(box Projection { + ref base, elem:ProjectionElem::Deref}) => { + + match *base { + Place::Local(local) => { + let locations = self.mir.find_assignments(local); + if locations.len() > 0 { + let item_msg = if error_reported { + match self.specialized_description(base){ + Some(msg) => msg, + None => self.get_main_error_message(place) + } + } else { + self.get_main_error_message(place) + }; + err_info = Some(( + self.mir.source_info(locations[0]).span, + "consider changing this to be a \ + mutable reference: `&mut`", item_msg, + "cannot assign through `&`-reference")); } - _ => {}, - } - } - _ => {} + }, + _ => {}, } - } - _ => {} + }, + _ => {}, } + + // match *place_err { + // Place::Projection(ref proj) => { + // match proj.elem { + // ProjectionElem::Deref => { + // match proj.base { + // Place::Local(local) => { + // let locations = self.mir.find_assignments(local); + // if locations.len() > 0 { + // let item_msg = if error_reported { + // match self.specialized_description(base){ + // Some(msg) => msg, + // None => self.get_main_error_message(place) + // } + // } else { + // self.get_main_error_message(place) + // }; + // err_info = Some(( + // self.mir.source_info(locations[0]).span, + // "consider changing this to be a \ + // mutable reference: `&mut`", item_msg, + // "cannot assign through `&`-reference")); + // } + // } + // _ => {}, + // } + // } + // _ => {} + // } + // } + // _ => {} + // } + if let Some((err_help_span, err_help_stmt, item_msg, sec_span)) = err_info { let mut err = self.tcx.cannot_assign(span, &item_msg, Origin::Mir, true); err.span_suggestion(err_help_span, err_help_stmt, format!("")); diff --git a/src/librustc_mir/util/borrowck_errors.rs b/src/librustc_mir/util/borrowck_errors.rs index 6c979de7a687..bcb3b605450d 100644 --- a/src/librustc_mir/util/borrowck_errors.rs +++ b/src/librustc_mir/util/borrowck_errors.rs @@ -284,8 +284,8 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { self.cancel_if_wrong_origin(err, o) } - fn cannot_assign(&self, span: Span, desc: &str, o: Origin, is_reference:bool) - -> DiagnosticBuilder + fn cannot_assign(self, span: Span, desc: &str, o: Origin, is_reference: bool) + -> DiagnosticBuilder<'cx> { let msg = if is_reference { "through"