diff options
| author | ashtneoi <ashtneoi@gmail.com> | 2018-07-10 23:23:13 -0700 |
|---|---|---|
| committer | ashtneoi <ashtneoi@gmail.com> | 2018-07-12 22:51:30 -0700 |
| commit | b8b04f6385ce9909a165ff47c5ebf49ded1fc6db (patch) | |
| tree | fd177ccbb5f2aab247ce967278035b62a0ea7520 /src | |
| parent | 6fd1a9fff79d906ecadcc9eab3962d84d38c7061 (diff) | |
| download | rust-b8b04f6385ce9909a165ff47c5ebf49ded1fc6db.tar.gz rust-b8b04f6385ce9909a165ff47c5ebf49ded1fc6db.zip | |
Put the two halves of suggest_ampmut back together
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/borrow_check/mod.rs | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 95601f13371..039f43cd213 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1850,22 +1850,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { binding_mode: ty::BindingMode::BindByValue(_), opt_ty_info, .. - }))) => { - if let Some(x) = try_suggest_ampmut_rhs( - self.tcx, self.mir, *local, - ) { - Some(x) - } else { - Some(suggest_ampmut_type(local_decl, opt_ty_info)) - } - }, + }))) => Some(suggest_ampmut( + self.tcx, + self.mir, + *local, + local_decl, + opt_ty_info, + )), Some(ClearCrossCrate::Set(mir::BindingForm::Var(mir::VarBindingForm { binding_mode: ty::BindingMode::BindByReference(_), .. - }))) => { - suggest_ref_mut(self.tcx, local_decl) - }, + }))) => suggest_ref_mut(self.tcx, local_decl), Some(ClearCrossCrate::Clear) => bug!("saw cleared local state"), @@ -1927,12 +1923,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // // This implementation attempts to emulate AST-borrowck prioritization // by trying (3.), then (2.) and finally falling back on (1.). - - fn try_suggest_ampmut_rhs<'cx, 'gcx, 'tcx>( + fn suggest_ampmut<'cx, 'gcx, 'tcx>( tcx: TyCtxt<'cx, 'gcx, 'tcx>, mir: &Mir<'tcx>, local: Local, - ) -> Option<(Span, String)> { + local_decl: &mir::LocalDecl<'tcx>, + opt_ty_info: Option<Span>, + ) -> (Span, String) { let locations = mir.find_assignments(local); if locations.len() > 0 { let assignment_rhs_span = mir.source_info(locations[0]).span; @@ -1940,17 +1937,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { if let Ok(src) = snippet { if src.starts_with('&') { let borrowed_expr = src[1..].to_string(); - return Some((assignment_rhs_span, format!("&mut {}", borrowed_expr))); + return ( + assignment_rhs_span, + format!("&mut {}", borrowed_expr), + ); } } } - None - } - fn suggest_ampmut_type<'tcx>( - local_decl: &mir::LocalDecl<'tcx>, - opt_ty_info: Option<Span>, - ) -> (Span, String) { let highlight_span = match opt_ty_info { // if this is a variable binding with an explicit type, // try to highlight that for the suggestion. |
