]> git.lizzy.rs Git - rust.git/commitdiff
struct error E0505
authorAndyJado <101876416+AndyJado@users.noreply.github.com>
Wed, 9 Nov 2022 12:57:44 +0000 (20:57 +0800)
committerAndyJado <101876416+AndyJado@users.noreply.github.com>
Wed, 9 Nov 2022 13:15:31 +0000 (21:15 +0800)
compiler/rustc_borrowck/src/borrowck_errors.rs
compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
compiler/rustc_borrowck/src/session_diagnostics.rs
compiler/rustc_error_messages/locales/en-US/borrowck.ftl

index 08ea00d71ef9d246620a96d91f16b1afde05dc0c..01be379120dc7483c088daa4005b744bb386dfb8 100644 (file)
@@ -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(
index 60860f93daa3cf13e8aec738f3ded26cd049d461..0f76cd1cdc1242824488d02474db9103d3d3388f 100644 (file)
@@ -667,10 +667,13 @@ pub(crate) fn report_move_out_while_borrowed(
         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);
 
index 3f9bfc5373aea34b8c56f7bf8ab906bcc44ac5ea..577332c0744b84dd8447af7ab3519a33ef18abe0 100644 (file)
@@ -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,
+}
index e3174360c90e26fa1135ee77868d81f34ccd8c7c..de47ada826444e00644e0edfc357973969a21f20 100644 (file)
@@ -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