diff options
| author | David Wood <david@davidtw.co> | 2018-10-05 14:30:45 +0200 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2018-10-08 12:26:56 +0200 |
| commit | 9e49ac067f205e4400e85c98e35c2fe9af820d7d (patch) | |
| tree | c1136430add61c23f1791ca1fe39892186cafb80 | |
| parent | f8c1b0cd5bdd603e7a0e1193f0dd7a6c9b0ebcc2 (diff) | |
| download | rust-9e49ac067f205e4400e85c98e35c2fe9af820d7d.tar.gz rust-9e49ac067f205e4400e85c98e35c2fe9af820d7d.zip | |
Change from label to suggestion.
This commit changes the label to a maybe incorrect suggestion for better integration with RLS.
| -rw-r--r-- | src/librustc_mir/borrow_check/mutability_errors.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/issue-38147-2.nll.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/issue-38147-3.nll.stderr | 2 |
3 files changed, 10 insertions, 7 deletions
diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index fe24ec382ce..5ab1605d7f0 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -241,7 +241,12 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { 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, ), )); diff --git a/src/test/ui/did_you_mean/issue-38147-2.nll.stderr b/src/test/ui/did_you_mean/issue-38147-2.nll.stderr index 91ccef1a32f..ebd44d46eb2 100644 --- a/src/test/ui/did_you_mean/issue-38147-2.nll.stderr +++ b/src/test/ui/did_you_mean/issue-38147-2.nll.stderr @@ -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 diff --git a/src/test/ui/did_you_mean/issue-38147-3.nll.stderr b/src/test/ui/did_you_mean/issue-38147-3.nll.stderr index ecc80a1d431..d644a84c7bb 100644 --- a/src/test/ui/did_you_mean/issue-38147-3.nll.stderr +++ b/src/test/ui/did_you_mean/issue-38147-3.nll.stderr @@ -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 |
