Skip to content

Commit 2cab61d

Browse files
committed
MutatingUpvar
1 parent 71d1762 commit 2cab61d

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// #![deny(rustc::untranslatable_diagnostic)]
2+
// #![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use rustc_errors::{
25
Applicability, Diagnostic, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed,
36
};
@@ -19,6 +22,7 @@ use rustc_span::symbol::{kw, Symbol};
1922
use rustc_span::{sym, BytePos, Span};
2023

2124
use crate::diagnostics::BorrowedContentSource;
25+
use crate::session_diagnostics::ShowMutatingUpvar;
2226
use crate::MirBorrowckCtxt;
2327
use rustc_const_eval::util::collect_writes::FindAssignments;
2428

@@ -864,14 +868,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
864868
} else {
865869
bug!("not an upvar")
866870
};
867-
err.span_label(
868-
*span,
869-
format!(
870-
"calling `{}` requires mutable binding due to {}",
871-
self.describe_place(the_place_err).unwrap(),
872-
reason
873-
),
874-
);
871+
let place = self.describe_place(the_place_err).unwrap();
872+
let sub_label = ShowMutatingUpvar::RequireMutableBinding { place, reason, span: *span };
873+
err.subdiagnostic(sub_label);
875874
}
876875
}
877876

compiler/rustc_borrowck/src/session_diagnostics.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,16 @@ pub(crate) enum MustValidFor<'a> {
321321
#[primary_span]
322322
span: Span,
323323
},
324+
}
324325

325-
#[label(borrowck::outlive_constraint_need_borrow_lasts_for)]
326-
Lasts {
327-
category: &'a str,
328-
borrow_desc: &'a str,
329-
region_name: &'a RegionName,
326+
//mutability_errors.rs
327+
328+
#[derive(SessionSubdiagnostic)]
329+
pub(crate) enum ShowMutatingUpvar {
330+
#[label(borrowck::require_mutable_binding)]
331+
RequireMutableBinding {
332+
place: String,
333+
reason: String,
330334
#[primary_span]
331335
span: Span,
332336
},

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,6 @@ borrowck_outlive_constraint_need_borrow_for =
130130
131131
borrowck_outlive_constraint_need_borrow_lasts_for =
132132
{$category}requires that `{$borrow_desc}` lasts for `{$region_name}`
133+
134+
borrowck_require_mutable_binding =
135+
calling `{$place}` requires mutable binding due to {$reason}

0 commit comments

Comments
 (0)