Skip to content

Commit 5fc91ad

Browse files
committed
eager_diag issue on diag struct
1 parent 05cc555 commit 5fc91ad

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

compiler/rustc_borrowck/messages.ftl

+26-26
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,37 @@ borrowck_assign_part_due_to_use_coroutine =
2424
assign to part occurs due to use in coroutine
2525
2626
borrowck_assign_place_behind_const_pointer =
27-
cannot assign to {$place}, which is behind a `*const` pointer
27+
cannot assign to `{$place}`, which is behind a `*const` pointer
2828
2929
borrowck_assign_place_behind_deref =
30-
cannot assign to {$place}, which is behind {$name}
30+
cannot assign to `{$place}`, which is behind {$name}
3131
3232
borrowck_assign_place_behind_index =
33-
cannot assign to {$place}, which is behind an index of {$ty}
33+
cannot assign to `{$place}`, which is behind an index of {$ty}
3434
3535
borrowck_assign_place_behind_ref =
36-
cannot assign to {$place}, which is behind a `&` reference
36+
cannot assign to `{$place}`, which is behind a `&` reference
3737
3838
borrowck_assign_place_declared_immute =
39-
cannot assign to {$place}, as it is not declared as mutable
39+
cannot assign to `{$place}`, as it is not declared as mutable
4040
4141
borrowck_assign_place_in_fn =
42-
cannot assign to {$place}, as it is a captured variable in a `Fn` closure
42+
cannot assign to `{$place}`, as it is a captured variable in a `Fn` closure
4343
4444
borrowck_assign_place_in_pattern_guard_immute =
45-
cannot assign to {$place}, as it is immutable for the pattern guard
45+
cannot assign to `{$place}`, as it is immutable for the pattern guard
4646
4747
borrowck_assign_place_static =
48-
cannot assign to immutable static item {$place}
48+
cannot assign to immutable static item `{$place}`
4949
5050
borrowck_assign_symbol_declared_immute =
51-
cannot assign to {$place}, as `{$name}` is not declared as mutable
51+
cannot assign to `{$place}`, as `{$name}` is not declared as mutable
5252
5353
borrowck_assign_symbol_static =
54-
cannot assign to {$place}, as `{$static_name}` is an immutable static item
54+
cannot assign to `{$place}`, as `{$static_name}` is an immutable static item
5555
5656
borrowck_assign_upvar_in_fn =
57-
cannot assign to {$place}, as `Fn` closures cannot mutate their captured variables
57+
cannot assign to `{$place}`, as `Fn` closures cannot mutate their captured variables
5858
5959
borrowck_borrow_due_to_use_closure =
6060
borrow occurs due to use in closure
@@ -96,13 +96,13 @@ borrowck_cannot_assign_to_borrowed =
9696
*[other] {$desc}
9797
} is borrowed here
9898
99+
borrowck_cannot_borrow_across_coroutine_yield =
100+
borrow may still be in use when {$coroutine_kind} yields
101+
.label = possible yield occurs here
102+
99103
borrowck_cannot_borrow_across_destructor =
100104
borrow may still be in use when destructor runs
101105
102-
borrowck_cannot_borrow_across_generator_yield =
103-
borrow may still be in use when generator yields
104-
.label = possible yield occurs here
105-
106106
borrowck_cannot_borrow_mut =
107107
cannot borrow as mutable
108108
@@ -396,37 +396,37 @@ borrowck_mut_borrow_data_behind_ref =
396396
cannot borrow data in a `&` reference as mutable
397397
398398
borrowck_mut_borrow_place_declared_immute =
399-
cannot borrow {$place} as mutable, as it is not declared as mutable
399+
cannot borrow `{$place}` as mutable, as it is not declared as mutable
400400
401401
borrowck_mut_borrow_place_in_pattern_guard_immute =
402-
cannot borrow {$place} as mutable, as it is immutable for the pattern guard
402+
cannot borrow `{$place}` as mutable, as it is immutable for the pattern guard
403403
404404
borrowck_mut_borrow_place_static =
405-
cannot borrow immutable static item {$place} as mutable
405+
cannot borrow immutable static item `{$place}` as mutable
406406
407407
borrowck_mut_borrow_self_behind_const_pointer =
408-
cannot borrow {$place} as mutable, as it is behind a `*const` pointer
408+
cannot borrow `{$place}` as mutable, as it is behind a `*const` pointer
409409
410410
borrowck_mut_borrow_self_behind_deref =
411-
cannot borrow {$place} as mutable, as it is behind {$name}
411+
cannot borrow `{$place}` as mutable, as it is behind {$name}
412412
413413
borrowck_mut_borrow_self_behind_index =
414-
cannot borrow {$place} as mutable, as it is behind an index of {$name}
414+
cannot borrow `{$place}` as mutable, as it is behind an index of {$name}
415415
416416
borrowck_mut_borrow_self_behind_ref =
417-
cannot borrow {$place} as mutable, as it is behind a `&` reference
417+
cannot borrow `{$place}` as mutable, as it is behind a `&` reference
418418
419419
borrowck_mut_borrow_self_in_fn =
420-
cannot borrow {$place} as mutable, as it is a captured variable in a `Fn` closure
420+
cannot borrow `{$place}` as mutable, as it is a captured variable in a `Fn` closure
421421
422422
borrowck_mut_borrow_symbol_declared_immute =
423-
cannot borrow {$place} as mutable, as `{$name}` is not declared as mutable
423+
cannot borrow `{$place}` as mutable, as `{$name}` is not declared as mutable
424424
425425
borrowck_mut_borrow_symbol_static =
426-
cannot borrow {$place} as mutable, as `{$static_name}` is an immutable static item
426+
cannot borrow `{$place}` as mutable, as `{$static_name}` is an immutable static item
427427
428428
borrowck_mut_borrow_upvar_in_fn =
429-
cannot borrow {$place} as mutable, as `Fn` closures cannot mutate their captured variables
429+
cannot borrow `{$place}` as mutable, as `Fn` closures cannot mutate their captured variables
430430
431431
borrowck_mutably_borrow_multiply_loop_label =
432432
{$is_place_empty ->

compiler/rustc_borrowck/src/borrowck_errors.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Span;
1010
use crate::{
1111
diagnostics::PlaceAndReason,
1212
session_diagnostics::{
13-
AssignBorrowErr, AssignErr, BorrowAcrossDestructor, BorrowAcrossGeneratorYield,
13+
AssignBorrowErr, AssignErr, BorrowAcrossCoroutineYield, BorrowAcrossDestructor,
1414
InteriorDropMoveErr, MutBorrowErr, PathShortLive, UseMutBorrowErr,
1515
},
1616
};
@@ -385,9 +385,6 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
385385
crate::diagnostics::BorrowedContentSource::DerefRawPointer => {
386386
MutBorrowErr::SelfBehindRawPointer { span, place }
387387
}
388-
crate::diagnostics::BorrowedContentSource::DerefMutableRef => {
389-
unreachable!()
390-
}
391388
crate::diagnostics::BorrowedContentSource::DerefSharedRef => {
392389
MutBorrowErr::SelfBehindSharedRef { span, place }
393390
}
@@ -405,6 +402,9 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
405402
name: name.unwrap_or_default(),
406403
}
407404
}
405+
crate::diagnostics::BorrowedContentSource::DerefMutableRef => {
406+
unreachable!()
407+
}
408408
}
409409
} else {
410410
match pointer_ty {
@@ -457,7 +457,13 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
457457
span: Span,
458458
yield_span: Span,
459459
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
460-
self.infcx.tcx.sess.create_err(BorrowAcrossGeneratorYield { span, yield_span })
460+
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
461+
let coroutine_kind = format!("{coroutine_kind:#}");
462+
self.infcx.tcx.sess.create_err(BorrowAcrossCoroutineYield {
463+
span,
464+
yield_span,
465+
coroutine_kind,
466+
})
461467
}
462468

463469
pub(crate) fn cannot_borrow_across_destructor(

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,7 @@ pub(super) struct DescribedPlace(pub(super) Option<String>);
6868

6969
impl IntoDiagnosticArg for DescribedPlace {
7070
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
71-
let mut desc = self.0;
72-
desc.as_mut().map(|s| {
73-
s.reserve(2);
74-
s.insert(0, '`');
75-
s.push('`');
76-
s
77-
});
78-
match desc {
71+
match self.0 {
7972
Some(descr) => descr.into_diagnostic_arg(),
8073
None => "value".into_diagnostic_arg(),
8174
}

compiler/rustc_borrowck/src/session_diagnostics.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,9 @@ pub(crate) struct BorrowAcrossDestructor {
633633
}
634634

635635
#[derive(Diagnostic)]
636-
#[diag(borrowck_cannot_borrow_across_generator_yield, code = "E0626")]
637-
pub(crate) struct BorrowAcrossGeneratorYield {
636+
#[diag(borrowck_cannot_borrow_across_coroutine_yield, code = "E0626")]
637+
pub(crate) struct BorrowAcrossCoroutineYield {
638+
pub coroutine_kind: String,
638639
#[primary_span]
639640
pub span: Span,
640641
#[label]

0 commit comments

Comments
 (0)