-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Diagnostic translation for borrow_check:errors
#112237
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use crate::session_diagnostics::CannotUseWhenMutablyBorrowed; | ||
use rustc_errors::{ | ||
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan, | ||
}; | ||
|
@@ -29,17 +30,12 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { | |
borrow_span: Span, | ||
borrow_desc: &str, | ||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { | ||
let mut err = struct_span_err!( | ||
self, | ||
self.infcx.tcx.sess.create_err(CannotUseWhenMutablyBorrowed { | ||
span, | ||
E0503, | ||
"cannot use {} because it was mutably borrowed", | ||
borrow_span, | ||
borrow_desc, | ||
desc, | ||
); | ||
|
||
err.span_label(borrow_span, format!("{} is borrowed here", borrow_desc)); | ||
err.span_label(span, format!("use of borrowed {}", borrow_desc)); | ||
Comment on lines
-40
to
-41
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. These labels weren't added to the ftl file, where did they go? 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. Should they be added as separate messages with their labels something like this
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. You should preserve all the error messages as much as possible |
||
err | ||
}) | ||
} | ||
|
||
pub(crate) fn cannot_mutably_borrow_multiply( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,17 @@ use rustc_span::Span; | |
|
||
use crate::diagnostics::RegionName; | ||
|
||
#[derive(Diagnostic)] | ||
#[diag(borrowck_cannot_use_when_mutably_borrowed, code = "E0503")] | ||
pub(crate) struct CannotUseWhenMutablyBorrowed<'a> { | ||
#[primary_span] | ||
pub span: Span, | ||
#[label] | ||
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. There is no corresponding 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 am still trying to understand how to use them, would just including the rest of the parameters under primary span work ? I can then just put their placeholders in the ftl file. I read the documentation but I was not really sure how to incorporate them in the .ftl file 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. Adding a
|
||
pub borrow_span: Span, | ||
pub borrow_desc: &'a str, | ||
pub desc: &'a str, | ||
} | ||
|
||
#[derive(Diagnostic)] | ||
#[diag(borrowck_move_unsized, code = "E0161")] | ||
pub(crate) struct MoveUnsized<'tcx> { | ||
|
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.
Why did you change the wording from here to "cannot use
{$desc}
when mutably borrowed"?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.
I read some of the examples in the ftl file and there were certain placeholders there so since desc would be put in here in the message I thought {desc} would be also substituted in the ftl file from the struct passed in.
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.
I might be completely wrong, feel free to correct me
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.
I meant, why did you change the wording? The old phrasing was "because it was mutably borrowed", the new phrasing is "when mutably borrowed"? I think we should separate diagnostics migration from tweaks of wording.