Skip to content

Commit 057d8e5

Browse files
committed
struct error E0505
1 parent abf259c commit 057d8e5

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
88
pub(crate) fn cannot_move_when_borrowed(
99
&self,
1010
span: Span,
11-
desc: &str,
11+
borrow_span: Span,
12+
place: &str,
13+
borrow_place: &str,
14+
value_place: &str,
1215
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
13-
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
16+
self.infcx.tcx.sess.create_err(crate::session_diagnostics::MoveBorrow {
17+
place,
18+
span,
19+
borrow_place,
20+
value_place,
21+
borrow_span,
22+
})
1423
}
1524

1625
pub(crate) fn cannot_use_when_mutably_borrowed(

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
667667
let move_spans = self.move_spans(place.as_ref(), location);
668668
let span = move_spans.args_or_use();
669669

670-
let mut err =
671-
self.cannot_move_when_borrowed(span, &self.describe_any_place(place.as_ref()));
672-
err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg));
673-
err.span_label(span, format!("move out of {} occurs here", value_msg));
670+
let mut err = self.cannot_move_when_borrowed(
671+
span,
672+
borrow_span,
673+
&self.describe_any_place(place.as_ref()),
674+
&borrow_msg,
675+
&value_msg,
676+
);
674677

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

compiler/rustc_borrowck/src/session_diagnostics.rs

+13
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,16 @@ pub(crate) enum CaptureVarCause {
227227
var_span: Span,
228228
},
229229
}
230+
231+
#[derive(Diagnostic)]
232+
#[diag(borrowck_cannot_move_when_borrowed, code = "E0505")]
233+
pub(crate) struct MoveBorrow<'a> {
234+
pub place: &'a str,
235+
pub borrow_place: &'a str,
236+
pub value_place: &'a str,
237+
#[primary_span]
238+
#[label(move_label)]
239+
pub span: Span,
240+
#[label]
241+
pub borrow_span: Span,
242+
}

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+14
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,17 @@ borrowck_var_move_by_use_place_in_generator =
109109
110110
borrowck_var_move_by_use_place_in_closure =
111111
move occurs due to use of {$place} in closure
112+
113+
borrowck_cannot_move_when_borrowed =
114+
cannot move out of {$place ->
115+
[value] value
116+
*[other] {$place}
117+
} because it is borrowed
118+
.label = borrow of {$borrow_place ->
119+
[value] value
120+
*[other] {$borrow_place}
121+
} occurs here
122+
.move_label = move out of {$value_place ->
123+
[value] value
124+
*[other] {$value_place}
125+
} occurs here

0 commit comments

Comments
 (0)