Skip to content

Commit 5a8c285

Browse files
committed
init
1 parent 8c6ce6b commit 5a8c285

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 7 additions & 8 deletions
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,14 @@ pub(crate) enum RequireStaticErr {
157157
multi_span: MultiSpan,
158158
},
159159
}
160+
//mutability_errors.rs
161+
#[derive(SessionSubdiagnostic)]
162+
pub(crate) enum ShowMutatingUpvar {
163+
#[label(borrowck::require_mutable_binding)]
164+
RequireMutableBinding {
165+
place: String,
166+
reason: String,
167+
#[primary_span]
168+
span: Span,
169+
},
170+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ borrowck_returned_lifetime_short =
5858
5959
borrowck_used_impl_require_static =
6060
the used `impl` has a `'static` requirement
61+
62+
borrowck_require_mutable_binding =
63+
calling `{$place}` requires mutable binding due to {$reason}

0 commit comments

Comments
 (0)