Skip to content
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

piece of diagnostic migrate #103960

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
struct error E0505
  • Loading branch information
AndyJado committed Nov 9, 2022
commit 057d8e5c43eb63691c5c6fbae8e67070150190f4
13 changes: 11 additions & 2 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
pub(crate) fn cannot_move_when_borrowed(
&self,
span: Span,
desc: &str,
borrow_span: Span,
place: &str,
borrow_place: &str,
value_place: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
self.infcx.tcx.sess.create_err(crate::session_diagnostics::MoveBorrow {
place,
span,
borrow_place,
value_place,
borrow_span,
})
}

pub(crate) fn cannot_use_when_mutably_borrowed(
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let move_spans = self.move_spans(place.as_ref(), location);
let span = move_spans.args_or_use();

let mut err =
self.cannot_move_when_borrowed(span, &self.describe_any_place(place.as_ref()));
err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg));
err.span_label(span, format!("move out of {} occurs here", value_msg));
let mut err = self.cannot_move_when_borrowed(
span,
borrow_span,
&self.describe_any_place(place.as_ref()),
&borrow_msg,
&value_msg,
);

borrow_spans.var_path_only_subdiag(&mut err, crate::InitializationRequiringAction::Borrow);

Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,16 @@ pub(crate) enum CaptureVarCause {
var_span: Span,
},
}

#[derive(Diagnostic)]
#[diag(borrowck_cannot_move_when_borrowed, code = "E0505")]
pub(crate) struct MoveBorrow<'a> {
pub place: &'a str,
pub borrow_place: &'a str,
pub value_place: &'a str,
#[primary_span]
#[label(move_label)]
pub span: Span,
#[label]
pub borrow_span: Span,
}
14 changes: 14 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/borrowck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,17 @@ borrowck_var_move_by_use_place_in_generator =

borrowck_var_move_by_use_place_in_closure =
move occurs due to use of {$place} in closure

borrowck_cannot_move_when_borrowed =
cannot move out of {$place ->
[value] value
*[other] {$place}
} because it is borrowed
.label = borrow of {$borrow_place ->
[value] value
*[other] {$borrow_place}
} occurs here
.move_label = move out of {$value_place ->
[value] value
*[other] {$value_place}
} occurs here