Skip to content

Commit

Permalink
eager_diag issue on diag struct
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyJado committed Nov 2, 2023
1 parent 05cc555 commit 5fc91ad
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
52 changes: 26 additions & 26 deletions compiler/rustc_borrowck/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Expand Down Expand Up @@ -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 }
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,7 @@ pub(super) struct DescribedPlace(pub(super) Option<String>);

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(),
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 5fc91ad

Please sign in to comment.