From e20a137d3c20ed7e4adf521666c2e6647db8cdb8 Mon Sep 17 00:00:00 2001 From: sladynnunes Date: Sat, 3 Jun 2023 01:57:57 -0700 Subject: [PATCH 1/3] Diagnostic translation --- compiler/rustc_borrowck/messages.ftl | 2 ++ .../rustc_borrowck/src/borrowck_errors.rs | 24 ++++++++++--------- .../rustc_borrowck/src/session_diagnostics.rs | 8 +++++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_borrowck/messages.ftl b/compiler/rustc_borrowck/messages.ftl index 67fdb671742da..f4221ea525815 100644 --- a/compiler/rustc_borrowck/messages.ftl +++ b/compiler/rustc_borrowck/messages.ftl @@ -19,6 +19,8 @@ borrowck_borrow_due_to_use_generator = borrowck_calling_operator_moves_lhs = calling this operator moves the left-hand side +borrowck_cannot_use_when_mutably_borrowed = cannot use `{$desc}` when mutably borrowed + borrowck_cannot_move_when_borrowed = cannot move out of {$place -> [value] value diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index acca1a1477f25..0617fb39e72e7 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -1,3 +1,4 @@ +use crate::session_diagnostics::CannotUseWhenMutablyBorrowed; use rustc_errors::{ struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan, }; @@ -29,17 +30,18 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { borrow_span: Span, borrow_desc: &str, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - let mut err = struct_span_err!( - self, - span, - E0503, - "cannot use {} because it was mutably borrowed", - desc, - ); - - err.span_label(borrow_span, format!("{} is borrowed here", borrow_desc)); - err.span_label(span, format!("use of borrowed {}", borrow_desc)); - err + create_err(CannotUseWhenMutablyBorrowed { span, desc }) + // let mut err = struct_span_err!( + // self, + // span, + // E0503, + // "cannot use {} because it was mutably borrowed", + // desc, + // ); + + // err.span_label(borrow_span, format!("{} is borrowed here", borrow_desc)); + // err.span_label(span, format!("use of borrowed {}", borrow_desc)); + // err } pub(crate) fn cannot_mutably_borrow_multiply( diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index fceae5bb3ffe0..9d6250898ba7a 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -5,6 +5,14 @@ use rustc_span::Span; use crate::diagnostics::RegionName; +#[derive(Diagnostic)] +#[diag(borrowck_cannot_use_when_mutably_borrowed)] +pub(crate) struct CannotUseWhenMutablyBorrowed { + #[primary_span] + pub span: Span, + desc: &'static str, +} + #[derive(Diagnostic)] #[diag(borrowck_move_unsized, code = "E0161")] pub(crate) struct MoveUnsized<'tcx> { From a9544754f2aebf8eb36afbab2551573f8a624996 Mon Sep 17 00:00:00 2001 From: sladynnunes Date: Sat, 3 Jun 2023 02:02:02 -0700 Subject: [PATCH 2/3] fixed linters --- compiler/rustc_borrowck/messages.ftl | 4 ++-- compiler/rustc_borrowck/src/session_diagnostics.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_borrowck/messages.ftl b/compiler/rustc_borrowck/messages.ftl index f4221ea525815..a0ce31d8b517b 100644 --- a/compiler/rustc_borrowck/messages.ftl +++ b/compiler/rustc_borrowck/messages.ftl @@ -19,8 +19,6 @@ borrowck_borrow_due_to_use_generator = borrowck_calling_operator_moves_lhs = calling this operator moves the left-hand side -borrowck_cannot_use_when_mutably_borrowed = cannot use `{$desc}` when mutably borrowed - borrowck_cannot_move_when_borrowed = cannot move out of {$place -> [value] value @@ -35,6 +33,8 @@ borrowck_cannot_move_when_borrowed = *[other] {$value_place} } occurs here +borrowck_cannot_use_when_mutably_borrowed = cannot use `{$desc}` when mutably borrowed + borrowck_capture_immute = capture is immutable because of use here diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 9d6250898ba7a..8afa65843daa2 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -6,7 +6,7 @@ use rustc_span::Span; use crate::diagnostics::RegionName; #[derive(Diagnostic)] -#[diag(borrowck_cannot_use_when_mutably_borrowed)] +#[diag(borrowck_cannot_use_when_mutably_borrowed, code = "E0503")] pub(crate) struct CannotUseWhenMutablyBorrowed { #[primary_span] pub span: Span, From 737b70c65bb34c2ae42893ebc65ebd418f85459c Mon Sep 17 00:00:00 2001 From: sladynnunes Date: Tue, 6 Jun 2023 23:47:41 -0700 Subject: [PATCH 3/3] commit suggestions --- compiler/rustc_borrowck/src/borrowck_errors.rs | 18 ++++++------------ .../rustc_borrowck/src/session_diagnostics.rs | 7 +++++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index 0617fb39e72e7..fa4100e3df729 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -30,18 +30,12 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { borrow_span: Span, borrow_desc: &str, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - create_err(CannotUseWhenMutablyBorrowed { span, desc }) - // let mut err = struct_span_err!( - // self, - // span, - // E0503, - // "cannot use {} because it was mutably borrowed", - // desc, - // ); - - // err.span_label(borrow_span, format!("{} is borrowed here", borrow_desc)); - // err.span_label(span, format!("use of borrowed {}", borrow_desc)); - // err + self.infcx.tcx.sess.create_err(CannotUseWhenMutablyBorrowed { + span, + borrow_span, + borrow_desc, + desc, + }) } pub(crate) fn cannot_mutably_borrow_multiply( diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 8afa65843daa2..6a155fc64f26b 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -7,10 +7,13 @@ use crate::diagnostics::RegionName; #[derive(Diagnostic)] #[diag(borrowck_cannot_use_when_mutably_borrowed, code = "E0503")] -pub(crate) struct CannotUseWhenMutablyBorrowed { +pub(crate) struct CannotUseWhenMutablyBorrowed<'a> { #[primary_span] pub span: Span, - desc: &'static str, + #[label] + pub borrow_span: Span, + pub borrow_desc: &'a str, + pub desc: &'a str, } #[derive(Diagnostic)]