-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Batch of improvements to errors for new error format #33619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f3054ce
104fe1c
1b6afd1
ecadd7e
6793cac
65cb5f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -624,9 +624,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
let mut db = self.struct_span_err( | ||
err.span, | ||
&self.bckerr_to_string(&err)); | ||
self.note_and_explain_bckerr(&mut db, err); | ||
db.span_label(span, &format!("cannot borrow")) | ||
.emit(); | ||
self.note_and_explain_bckerr(&mut db, err, span); | ||
db.emit(); | ||
} | ||
|
||
pub fn report_use_of_moved_value(&self, | ||
|
@@ -721,10 +720,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
err.span_label( | ||
use_span, | ||
&format!("value moved{} here in previous iteration of loop", | ||
move_note)) | ||
move_note)); | ||
err | ||
} else { | ||
err.span_label(use_span, &format!("value {} here after move", verb_participle)) | ||
.span_label(move_span, &format!("value moved{} here", move_note)) | ||
.span_label(move_span, &format!("value moved{} here", move_note)); | ||
err | ||
}; | ||
|
||
err.note(&format!("move occurs because `{}` has type `{}`, \ | ||
|
@@ -951,7 +952,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
.emit(); | ||
} | ||
|
||
pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<'tcx>) { | ||
pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<'tcx>, | ||
error_span: Span) { | ||
let code = err.code; | ||
match code { | ||
err_mutbl => { | ||
|
@@ -976,13 +978,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
let span = self.tcx.map.span(local_id); | ||
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) { | ||
if snippet != "self" { | ||
db.span_suggestion( | ||
span, | ||
&format!("to make the {} mutable, use `mut` as shown:", | ||
self.cmt_to_string(&err.cmt)), | ||
format!("mut {}", snippet)); | ||
db.span_label(span, | ||
&format!("use `mut {}` here to make mutable", snippet)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This replaced span_suggestion with span_label, which is undesirable. See #33691. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should chat about lint implications. For the actual error, moving it to a label text appears to improve readability "at a glance" of the errors. That said, we may want to distinguish them in some way that lints and autocorrection type tools can find and use them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
} | ||
} | ||
db.span_label(error_span, &format!("cannot borrow mutably")); | ||
} | ||
} | ||
} | ||
|
@@ -1000,6 +1000,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
super_scope, | ||
""); | ||
if let Some(span) = statement_scope_span(self.tcx, super_scope) { | ||
db.span_label(error_span, &format!("does not live long enough")); | ||
db.span_help(span, | ||
"consider using a `let` binding to increase its lifetime"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after
=