Skip to content

Commit 3852fd9

Browse files
Convert to inline diagnostics in rustc_borrowck
1 parent 930ecbc commit 3852fd9

9 files changed

Lines changed: 232 additions & 394 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,7 +3573,6 @@ dependencies = [
35733573
"rustc_abi",
35743574
"rustc_data_structures",
35753575
"rustc_errors",
3576-
"rustc_fluent_macro",
35773576
"rustc_graphviz",
35783577
"rustc_hir",
35793578
"rustc_index",
@@ -3778,7 +3777,6 @@ dependencies = [
37783777
"rustc_ast_lowering",
37793778
"rustc_ast_passes",
37803779
"rustc_ast_pretty",
3781-
"rustc_borrowck",
37823780
"rustc_builtin_macros",
37833781
"rustc_codegen_ssa",
37843782
"rustc_const_eval",

compiler/rustc_borrowck/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ polonius-engine = "0.13.0"
1111
rustc_abi = { path = "../rustc_abi" }
1212
rustc_data_structures = { path = "../rustc_data_structures" }
1313
rustc_errors = { path = "../rustc_errors" }
14-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1514
rustc_graphviz = { path = "../rustc_graphviz" }
1615
rustc_hir = { path = "../rustc_hir" }
1716
rustc_index = { path = "../rustc_index" }

compiler/rustc_borrowck/messages.ftl

Lines changed: 0 additions & 296 deletions
This file was deleted.

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::collections::BTreeMap;
44

55
use rustc_abi::{FieldIdx, VariantIdx};
66
use rustc_data_structures::fx::FxIndexMap;
7-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, listify};
7+
use rustc_errors::{
8+
Applicability, Diag, DiagMessage, EmissionGuarantee, MultiSpan, inline_fluent, listify,
9+
};
810
use rustc_hir::def::{CtorKind, Namespace};
911
use rustc_hir::{
1012
self as hir, CoroutineKind, GenericBound, LangItem, WhereBoundPredicate, WherePredicateKind,
@@ -35,7 +37,6 @@ use tracing::debug;
3537
use super::MirBorrowckCtxt;
3638
use super::borrow_set::BorrowData;
3739
use crate::constraints::OutlivesConstraint;
38-
use crate::fluent_generated as fluent;
3940
use crate::nll::ConstraintDescription;
4041
use crate::session_diagnostics::{
4142
CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause,
@@ -664,6 +665,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
664665
diag: &mut Diag<'_, G>,
665666
path: &[OutlivesConstraint<'tcx>],
666667
) {
668+
const BORROWCK_LIMITATION_IMPLIES_STATIC: DiagMessage = inline_fluent!(
669+
"due to a current limitation of the type system, this implies a `'static` lifetime"
670+
);
671+
667672
let tcx = self.infcx.tcx;
668673
let Some((gat_hir_id, generics)) = path.iter().find_map(|constraint| {
669674
let outlived = constraint.sub;
@@ -700,7 +705,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
700705
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
701706
.is_some()
702707
{
703-
diag.span_note(pred.span, fluent::borrowck_limitations_implies_static);
708+
diag.span_note(pred.span, BORROWCK_LIMITATION_IMPLIES_STATIC);
704709
return;
705710
}
706711
for bound in bounds.iter() {
@@ -711,7 +716,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
711716
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
712717
.is_some()
713718
{
714-
diag.span_note(bound.span, fluent::borrowck_limitations_implies_static);
719+
diag.span_note(bound.span, BORROWCK_LIMITATION_IMPLIES_STATIC);
715720
return;
716721
}
717722
}
@@ -1312,7 +1317,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13121317
let mut span: MultiSpan = spans.clone().into();
13131318
err.arg("ty", param_ty.to_string());
13141319
let msg = err.dcx.eagerly_translate_to_string(
1315-
fluent::borrowck_moved_a_fn_once_in_call_def,
1320+
inline_fluent!("`{$ty}` is made to be an `FnOnce` closure here"),
13161321
err.args.iter(),
13171322
);
13181323
err.remove_arg("ty");
@@ -1321,9 +1326,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13211326
}
13221327
span.push_span_label(
13231328
fn_call_span,
1324-
fluent::borrowck_moved_a_fn_once_in_call,
1329+
inline_fluent!("this value implements `FnOnce`, which causes it to be moved when called"),
1330+
);
1331+
err.span_note(
1332+
span,
1333+
inline_fluent!("`FnOnce` closures can only be called once"),
13251334
);
1326-
err.span_note(span, fluent::borrowck_moved_a_fn_once_in_call_call);
13271335
} else {
13281336
err.subdiagnostic(CaptureReasonNote::FnOnceMoveInCall { var_span });
13291337
}

0 commit comments

Comments
 (0)