]> git.lizzy.rs Git - rust.git/commitdiff
Change from label to suggestion.
authorDavid Wood <david@davidtw.co>
Fri, 5 Oct 2018 12:30:45 +0000 (14:30 +0200)
committerDavid Wood <david@davidtw.co>
Mon, 8 Oct 2018 10:26:56 +0000 (12:26 +0200)
This commit changes the label to a maybe incorrect suggestion for better
integration with RLS.

src/librustc_mir/borrow_check/mutability_errors.rs
src/test/ui/did_you_mean/issue-38147-2.nll.stderr
src/test/ui/did_you_mean/issue-38147-3.nll.stderr

index fe24ec382ceb354bc912478faa1e30787a1366b1..5ab1605d7f07ab404fc79d2ae791a68fe8a5412e 100644 (file)
@@ -241,7 +241,12 @@ pub(super) fn report_mutability_error(
                     base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
                     field,
                 ) {
-                    err.span_label(span, message);
+                    err.span_suggestion_with_applicability(
+                        span,
+                        "consider changing this to be mutable",
+                        message,
+                        Applicability::MaybeIncorrect,
+                    );
                 }
             },
 
@@ -636,8 +641,6 @@ fn annotate_struct_field(
     if let ty::TyKind::Ref(_, ty, _) = ty.sty {
         if let ty::TyKind::Adt(def, _) = ty.sty {
             let field = def.all_fields().nth(field.index())?;
-            let span = tcx.def_span(field.did);
-
             // Use the HIR types to construct the diagnostic message.
             let node_id = tcx.hir.as_local_node_id(field.did)?;
             let node = tcx.hir.find(node_id)?;
@@ -659,9 +662,9 @@ fn annotate_struct_field(
                     };
 
                     return Some((
-                        span,
+                        field.ty.span,
                         format!(
-                            "use `&{}mut {}` here to make mutable",
+                            "&{}mut {}",
                             lifetime_snippet, &*type_snippet,
                         ),
                     ));
index 91ccef1a32f1f22f7e5e4b9f5bb8fa92b8c6aea7..ebd44d46eb2ce544eb8e082a9e58dfc194d64ac0 100644 (file)
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` referenc
   --> $DIR/issue-38147-2.rs:17:9
    |
 LL |     s: &'a String
-   |     ------------- use `&'a mut String` here to make mutable
+   |        ---------- help: consider changing this to be mutable: `&'a mut String`
 ...
 LL |         self.s.push('x');
    |         ^^^^^^ cannot borrow as mutable
index ecc80a1d4310bae0c711cb86a6ad8a2865f7f702..d644a84c7bbcec2da5723cf079f523f68c0746ae 100644 (file)
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` referenc
   --> $DIR/issue-38147-3.rs:17:9
    |
 LL |     s: &'a String
-   |     ------------- use `&'a mut String` here to make mutable
+   |        ---------- help: consider changing this to be mutable: `&'a mut String`
 ...
 LL |         self.s.push('x');
    |         ^^^^^^ cannot borrow as mutable