diff --git a/compiler/rustc_borrowck/messages.ftl b/compiler/rustc_borrowck/messages.ftl index 989267adb59ce..aae14d847f2e8 100644 --- a/compiler/rustc_borrowck/messages.ftl +++ b/compiler/rustc_borrowck/messages.ftl @@ -24,37 +24,37 @@ borrowck_assign_part_due_to_use_coroutine = assign to part occurs due to use in coroutine borrowck_assign_place_behind_const_pointer = - cannot assign to {$place}, which is behind a `*const` pointer + cannot assign to `{$place}`, which is behind a `*const` pointer borrowck_assign_place_behind_deref = - cannot assign to {$place}, which is behind {$name} + cannot assign to `{$place}`, which is behind {$name} borrowck_assign_place_behind_index = - cannot assign to {$place}, which is behind an index of {$ty} + cannot assign to `{$place}`, which is behind an index of {$ty} borrowck_assign_place_behind_ref = - cannot assign to {$place}, which is behind a `&` reference + cannot assign to `{$place}`, which is behind a `&` reference borrowck_assign_place_declared_immute = - cannot assign to {$place}, as it is not declared as mutable + cannot assign to `{$place}`, as it is not declared as mutable borrowck_assign_place_in_fn = - cannot assign to {$place}, as it is a captured variable in a `Fn` closure + cannot assign to `{$place}`, as it is a captured variable in a `Fn` closure borrowck_assign_place_in_pattern_guard_immute = - cannot assign to {$place}, as it is immutable for the pattern guard + cannot assign to `{$place}`, as it is immutable for the pattern guard borrowck_assign_place_static = - cannot assign to immutable static item {$place} + cannot assign to immutable static item `{$place}` borrowck_assign_symbol_declared_immute = - cannot assign to {$place}, as `{$name}` is not declared as mutable + cannot assign to `{$place}`, as `{$name}` is not declared as mutable borrowck_assign_symbol_static = - cannot assign to {$place}, as `{$static_name}` is an immutable static item + cannot assign to `{$place}`, as `{$static_name}` is an immutable static item borrowck_assign_upvar_in_fn = - cannot assign to {$place}, as `Fn` closures cannot mutate their captured variables + cannot assign to `{$place}`, as `Fn` closures cannot mutate their captured variables borrowck_borrow_due_to_use_closure = borrow occurs due to use in closure @@ -96,13 +96,13 @@ borrowck_cannot_assign_to_borrowed = *[other] {$desc} } is borrowed here +borrowck_cannot_borrow_across_coroutine_yield = + borrow may still be in use when {$coroutine_kind} yields + .label = possible yield occurs here + borrowck_cannot_borrow_across_destructor = borrow may still be in use when destructor runs -borrowck_cannot_borrow_across_generator_yield = - borrow may still be in use when generator yields - .label = possible yield occurs here - borrowck_cannot_borrow_mut = cannot borrow as mutable @@ -396,37 +396,37 @@ borrowck_mut_borrow_data_behind_ref = cannot borrow data in a `&` reference as mutable borrowck_mut_borrow_place_declared_immute = - cannot borrow {$place} as mutable, as it is not declared as mutable + cannot borrow `{$place}` as mutable, as it is not declared as mutable borrowck_mut_borrow_place_in_pattern_guard_immute = - cannot borrow {$place} as mutable, as it is immutable for the pattern guard + cannot borrow `{$place}` as mutable, as it is immutable for the pattern guard borrowck_mut_borrow_place_static = - cannot borrow immutable static item {$place} as mutable + cannot borrow immutable static item `{$place}` as mutable borrowck_mut_borrow_self_behind_const_pointer = - cannot borrow {$place} as mutable, as it is behind a `*const` pointer + cannot borrow `{$place}` as mutable, as it is behind a `*const` pointer borrowck_mut_borrow_self_behind_deref = - cannot borrow {$place} as mutable, as it is behind {$name} + cannot borrow `{$place}` as mutable, as it is behind {$name} borrowck_mut_borrow_self_behind_index = - cannot borrow {$place} as mutable, as it is behind an index of {$name} + cannot borrow `{$place}` as mutable, as it is behind an index of {$name} borrowck_mut_borrow_self_behind_ref = - cannot borrow {$place} as mutable, as it is behind a `&` reference + cannot borrow `{$place}` as mutable, as it is behind a `&` reference borrowck_mut_borrow_self_in_fn = - cannot borrow {$place} as mutable, as it is a captured variable in a `Fn` closure + cannot borrow `{$place}` as mutable, as it is a captured variable in a `Fn` closure borrowck_mut_borrow_symbol_declared_immute = - cannot borrow {$place} as mutable, as `{$name}` is not declared as mutable + cannot borrow `{$place}` as mutable, as `{$name}` is not declared as mutable borrowck_mut_borrow_symbol_static = - cannot borrow {$place} as mutable, as `{$static_name}` is an immutable static item + cannot borrow `{$place}` as mutable, as `{$static_name}` is an immutable static item borrowck_mut_borrow_upvar_in_fn = - cannot borrow {$place} as mutable, as `Fn` closures cannot mutate their captured variables + cannot borrow `{$place}` as mutable, as `Fn` closures cannot mutate their captured variables borrowck_mutably_borrow_multiply_loop_label = {$is_place_empty -> diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index aa58b0ab2d66d..b00f03c1aba05 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -10,7 +10,7 @@ use rustc_span::Span; use crate::{ diagnostics::PlaceAndReason, session_diagnostics::{ - AssignBorrowErr, AssignErr, BorrowAcrossDestructor, BorrowAcrossGeneratorYield, + AssignBorrowErr, AssignErr, BorrowAcrossCoroutineYield, BorrowAcrossDestructor, InteriorDropMoveErr, MutBorrowErr, PathShortLive, UseMutBorrowErr, }, }; @@ -385,9 +385,6 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { crate::diagnostics::BorrowedContentSource::DerefRawPointer => { MutBorrowErr::SelfBehindRawPointer { span, place } } - crate::diagnostics::BorrowedContentSource::DerefMutableRef => { - unreachable!() - } crate::diagnostics::BorrowedContentSource::DerefSharedRef => { MutBorrowErr::SelfBehindSharedRef { span, place } } @@ -405,6 +402,9 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { name: name.unwrap_or_default(), } } + crate::diagnostics::BorrowedContentSource::DerefMutableRef => { + unreachable!() + } } } else { match pointer_ty { @@ -457,7 +457,13 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { span: Span, yield_span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - self.infcx.tcx.sess.create_err(BorrowAcrossGeneratorYield { span, yield_span }) + let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind; + let coroutine_kind = format!("{coroutine_kind:#}"); + self.infcx.tcx.sess.create_err(BorrowAcrossCoroutineYield { + span, + yield_span, + coroutine_kind, + }) } pub(crate) fn cannot_borrow_across_destructor( diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 0c3377d609970..784120f23717c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -68,14 +68,7 @@ pub(super) struct DescribedPlace(pub(super) Option); impl IntoDiagnosticArg for DescribedPlace { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { - let mut desc = self.0; - desc.as_mut().map(|s| { - s.reserve(2); - s.insert(0, '`'); - s.push('`'); - s - }); - match desc { + match self.0 { Some(descr) => descr.into_diagnostic_arg(), None => "value".into_diagnostic_arg(), } diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index e80f347012539..bf36a85d03d7f 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -633,8 +633,9 @@ pub(crate) struct BorrowAcrossDestructor { } #[derive(Diagnostic)] -#[diag(borrowck_cannot_borrow_across_generator_yield, code = "E0626")] -pub(crate) struct BorrowAcrossGeneratorYield { +#[diag(borrowck_cannot_borrow_across_coroutine_yield, code = "E0626")] +pub(crate) struct BorrowAcrossCoroutineYield { + pub coroutine_kind: String, #[primary_span] pub span: Span, #[label]