Skip to content

Commit 9e49ac0

Browse files
committed
Change from label to suggestion.
This commit changes the label to a maybe incorrect suggestion for better integration with RLS.
1 parent f8c1b0c commit 9e49ac0

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/librustc_mir/borrow_check/mutability_errors.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
241241
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
242242
field,
243243
) {
244-
err.span_label(span, message);
244+
err.span_suggestion_with_applicability(
245+
span,
246+
"consider changing this to be mutable",
247+
message,
248+
Applicability::MaybeIncorrect,
249+
);
245250
}
246251
},
247252

@@ -636,8 +641,6 @@ fn annotate_struct_field(
636641
if let ty::TyKind::Ref(_, ty, _) = ty.sty {
637642
if let ty::TyKind::Adt(def, _) = ty.sty {
638643
let field = def.all_fields().nth(field.index())?;
639-
let span = tcx.def_span(field.did);
640-
641644
// Use the HIR types to construct the diagnostic message.
642645
let node_id = tcx.hir.as_local_node_id(field.did)?;
643646
let node = tcx.hir.find(node_id)?;
@@ -659,9 +662,9 @@ fn annotate_struct_field(
659662
};
660663

661664
return Some((
662-
span,
665+
field.ty.span,
663666
format!(
664-
"use `&{}mut {}` here to make mutable",
667+
"&{}mut {}",
665668
lifetime_snippet, &*type_snippet,
666669
),
667670
));

src/test/ui/did_you_mean/issue-38147-2.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` referenc
22
--> $DIR/issue-38147-2.rs:17:9
33
|
44
LL | s: &'a String
5-
| ------------- use `&'a mut String` here to make mutable
5+
| ---------- help: consider changing this to be mutable: `&'a mut String`
66
...
77
LL | self.s.push('x');
88
| ^^^^^^ cannot borrow as mutable

src/test/ui/did_you_mean/issue-38147-3.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` referenc
22
--> $DIR/issue-38147-3.rs:17:9
33
|
44
LL | s: &'a String
5-
| ------------- use `&'a mut String` here to make mutable
5+
| ---------- help: consider changing this to be mutable: `&'a mut String`
66
...
77
LL | self.s.push('x');
88
| ^^^^^^ cannot borrow as mutable

0 commit comments

Comments
 (0)