]> git.lizzy.rs Git - rust.git/commitdiff
Put the two halves of suggest_ampmut back together
authorashtneoi <ashtneoi@gmail.com>
Wed, 11 Jul 2018 06:23:13 +0000 (23:23 -0700)
committerashtneoi <ashtneoi@gmail.com>
Fri, 13 Jul 2018 05:51:30 +0000 (22:51 -0700)
src/librustc_mir/borrow_check/mod.rs

index 95601f1337139cd5a2b7456fb543dd69b415088d..039f43cd213f7f71b94de7b70fed8fcb8a9a5169 100644 (file)
@@ -1850,22 +1850,18 @@ enum AccessKind {
                         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 @@ fn suggest_ampmut_self<'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 @@ fn try_suggest_ampmut_rhs<'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.