Skip to content

Commit e924fd8

Browse files
committed
nit fix
1 parent 8ebc364 commit e924fd8

File tree

7 files changed

+26
-41
lines changed

7 files changed

+26
-41
lines changed

compiler/rustc_borrowck/messages.ftl

-13
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,6 @@ borrowck_path_does_not_live_long_enough =
474474
borrowck_perhaps_save_in_new_local_to_drop =
475475
for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
476476
477-
borrowck_require_mutable_binding =
478-
calling `{$place}` requires mutable binding due to {$reason ->
479-
[borrow] mutable borrow of `{$upvar}`
480-
*[mutation] possible mutation of `{$upvar}`
481-
}
482-
483477
borrowck_return_fnmut =
484478
change this to return `FnMut` instead of `Fn`
485479
@@ -536,13 +530,6 @@ borrowck_used_here_by_closure =
536530
borrowck_used_impl_require_static =
537531
the used `impl` has a `'static` requirement
538532
539-
borrowck_used_non_generic_for_generic =
540-
used non-generic {$descr ->
541-
[lifetime] lifetime
542-
[type] type
543-
*[constant] constant
544-
} `{$arg}` for generic parameter
545-
546533
borrowck_value_capture_here =
547534
value captured {$is_within ->
548535
[true] here by coroutine

compiler/rustc_borrowck/src/borrowck_errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
5353
old_load_end_span: Option<Span>,
5454
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
5555
use crate::session_diagnostics::MutBorrowMulti::*;
56-
let via = |msg: &str| msg.is_empty();
56+
let via = place.is_empty();
5757
self.infcx.tcx.sess.create_err(if old_loan_span == new_loan_span {
5858
// Both borrows are happening in the same place
5959
// Meaning the borrow is occurring in a loop
6060
SameSpan {
6161
new_place_name,
6262
place,
6363
old_place,
64-
is_place_empty: via(place),
64+
is_place_empty: via,
6565
new_loan_span,
6666
old_load_end_span,
6767
eager_label: crate::session_diagnostics::MutMultiLoopLabel {
6868
new_place_name,
6969
place,
70-
is_place_empty: via(place),
70+
is_place_empty: via,
7171
new_loan_span,
7272
},
7373
}
@@ -76,8 +76,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
7676
new_place_name,
7777
place,
7878
old_place,
79-
is_place_empty: via(place),
80-
is_old_place_empty: via(old_place),
79+
is_place_empty: via,
80+
is_old_place_empty: old_place.is_empty(),
8181
new_loan_span,
8282
old_loan_span,
8383
old_load_end_span,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17951795
/// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
17961796
/// mutable (via `a.u.s.b`) [E0502]
17971797
/// ```
1798-
// FIXME: first 3 out of 4 can contain English word value, note for diagnostic migration
1798+
// FIXME(#100717): In the return value, the first three strings can contain untranslated text.
17991799
pub(crate) fn describe_place_for_conflicting_borrow(
18001800
&self,
18011801
first_borrowed_place: Place<'tcx>,

compiler/rustc_borrowck/src/diagnostics/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,6 @@ impl<'tcx> BorrowedContentSource<'tcx> {
719719
}
720720
}
721721

722-
// ready to remove
723722
pub(super) fn describe_for_immutable_place(&self, tcx: TyCtxt<'_>) -> Option<String> {
724723
match *self {
725724
BorrowedContentSource::DerefRawPointer => None,

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
6161

6262
let mut err;
6363
let item_msg;
64-
let diagnosing: PlaceAndReason<'_>;
64+
let diagnostic: PlaceAndReason<'_>;
6565
let mut opt_source = None;
6666
let access_place_desc = self.describe_any_place(access_place.as_ref());
6767
debug!("report_mutability_error: access_place_desc={:?}", access_place_desc);
@@ -102,7 +102,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
102102
return;
103103
} else {
104104
item_msg = access_place_desc;
105-
diagnosing = if self.is_upvar_field_projection(access_place.as_ref()).is_some()
105+
diagnostic = if self.is_upvar_field_projection(access_place.as_ref()).is_some()
106106
{
107107
PlaceAndReason::DeclaredImmute(item_msg.clone(), None)
108108
} else {
@@ -116,7 +116,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
116116
if self.body.local_decls[local].is_ref_for_guard() =>
117117
{
118118
item_msg = access_place_desc;
119-
diagnosing = PlaceAndReason::InPatternGuard(item_msg.clone())
119+
diagnostic = PlaceAndReason::InPatternGuard(access_place_desc)
120120
}
121121
PlaceRef { local, projection: [ProjectionElem::Deref] }
122122
if self.body.local_decls[local].is_ref_to_static() =>
@@ -145,7 +145,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
145145
the_place_err.ty(self.body, self.infcx.tcx).ty
146146
));
147147

148-
diagnosing = if self.is_upvar_field_projection(access_place.as_ref()).is_some()
148+
diagnostic = if self.is_upvar_field_projection(access_place.as_ref()).is_some()
149149
{
150150
PlaceAndReason::SelfCaptured(item_msg.clone())
151151
} else {
@@ -196,14 +196,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
196196
let mut mut_error = None;
197197
let mut count = 1;
198198

199-
let cant_access_here = |sp: Span| match error_access {
199+
let access_diagnose_builder = |sp: Span| match error_access {
200200
AccessKind::MutableBorrow => FnMutBumpFn::CannotBorrowMut { sp },
201201
AccessKind::Mutate => FnMutBumpFn::CannotAssign { sp },
202202
};
203203
let span = match error_access {
204-
// cannot assign only happen in Mutate
205204
AccessKind::Mutate => {
206-
err = self.cannot_assign(span, diagnosing);
205+
err = self.cannot_assign(span, diagnostic);
207206
act = "assign";
208207
acted_on = "written";
209208
span
@@ -234,11 +233,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
234233
suggest = false;
235234
} else {
236235
err =
237-
self.cannot_borrow_path_as_mutable_because(borrow_span, diagnosing);
236+
self.cannot_borrow_path_as_mutable_because(borrow_span, diagnostic);
238237
}
239238
}
240239
_ => {
241-
err = self.cannot_borrow_path_as_mutable_because(borrow_span, diagnosing);
240+
err = self.cannot_borrow_path_as_mutable_because(borrow_span, diagnostic);
242241
}
243242
}
244243
if suggest {
@@ -278,7 +277,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
278277
ProjectionElem::Deref,
279278
],
280279
} => {
281-
err.subdiagnostic(cant_access_here(span));
280+
err.subdiagnostic(access_diagnose_builder(span));
282281

283282
let place = Place::ty_from(local, proj_base, self.body, self.infcx.tcx);
284283
if let Some(span) = get_mut_span_in_struct_field(self.infcx.tcx, place.ty, *field) {
@@ -300,7 +299,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
300299
.is_some_and(|l| mut_borrow_of_mutable_ref(l, self.local_names[local])) =>
301300
{
302301
let decl = &self.body.local_decls[local];
303-
err.subdiagnostic(cant_access_here(span));
302+
err.subdiagnostic(access_diagnose_builder(span));
304303
if let Some(mir::Statement {
305304
source_info,
306305
kind:
@@ -385,7 +384,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
385384
assert_eq!(local_decl.mutability, Mutability::Not);
386385

387386
if count < 10 {
388-
err.subdiagnostic(cant_access_here(span));
387+
err.subdiagnostic(access_diagnose_builder(span));
389388
}
390389
if suggest {
391390
self.construct_mut_suggestion_for_local_binding_patterns(&mut err, local);
@@ -407,7 +406,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
407406

408407
let captured_place = &self.upvars[upvar_index.index()].place;
409408

410-
err.subdiagnostic(cant_access_here(span));
409+
err.subdiagnostic(access_diagnose_builder(span));
411410

412411
let upvar_hir_id = captured_place.get_root_variable();
413412

@@ -462,7 +461,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
462461
.span_to_snippet(span)
463462
.is_ok_and(|snippet| snippet.starts_with("&mut ")) =>
464463
{
465-
err.subdiagnostic(cant_access_here(span));
464+
err.subdiagnostic(access_diagnose_builder(span));
466465
err.span_suggestion(
467466
span,
468467
"try removing `&mut` here",
@@ -474,7 +473,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
474473
PlaceRef { local, projection: [ProjectionElem::Deref] }
475474
if self.body.local_decls[local].is_ref_for_guard() =>
476475
{
477-
err.subdiagnostic(cant_access_here(span));
476+
err.subdiagnostic(access_diagnose_builder(span));
478477
err.note(
479478
"variables bound in patterns are immutable until the end of the pattern guard",
480479
);
@@ -518,12 +517,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
518517
PlaceRef { local, projection: [ProjectionElem::Deref] }
519518
if local == ty::CAPTURE_STRUCT_LOCAL && !self.upvars.is_empty() =>
520519
{
521-
err.subdiagnostic(cant_access_here(span));
520+
err.subdiagnostic(access_diagnose_builder(span));
522521
self.expected_fn_found_fn_mut_call(&mut err);
523522
}
524523

525524
PlaceRef { local: _, projection: [.., ProjectionElem::Deref] } => {
526-
err.subdiagnostic(cant_access_here(span));
525+
err.subdiagnostic(access_diagnose_builder(span));
527526

528527
match opt_source {
529528
Some(BorrowedContentSource::OverloadedDeref(ty)) => {
@@ -544,7 +543,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
544543
}
545544

546545
_ => {
547-
err.subdiagnostic(cant_access_here(span));
546+
err.subdiagnostic(access_diagnose_builder(span));
548547
}
549548
}
550549

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl RegionName {
160160
RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => {
161161
diag.subdiagnostic(RegionNameLabels::LifetimeInTypeOf {
162162
span: *span,
163-
upvar_name: upvar_name.to_ident_string(),
163+
upvar_name,
164164
rg_name: self,
165165
});
166166
}

compiler/rustc_borrowck/src/session_diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_errors::MultiSpan;
22
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
33
use rustc_middle::ty::{GenericArg, Ty};
4-
use rustc_span::Span;
4+
use rustc_span::{Span, Symbol};
55

66
use crate::diagnostics::RegionName;
77

@@ -540,7 +540,7 @@ pub(crate) enum RegionNameLabels<'a> {
540540
LifetimeInTypeOf {
541541
#[primary_span]
542542
span: Span,
543-
upvar_name: String,
543+
upvar_name: &'a Symbol,
544544
rg_name: &'a RegionName,
545545
},
546546
#[label(borrowck_yield_type_is_type)]

0 commit comments

Comments
 (0)