Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a1f7ac1

Browse files
committedFeb 23, 2024
diag message migration, can't fix backtick repeat
1 parent 397937d commit a1f7ac1

File tree

11 files changed

+1352
-305
lines changed

11 files changed

+1352
-305
lines changed
 

‎compiler/rustc_borrowck/messages.ftl

Lines changed: 356 additions & 8 deletions
Large diffs are not rendered by default.

‎compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 222 additions & 162 deletions
Large diffs are not rendered by default.

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19171917
/// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
19181918
/// mutable (via `a.u.s.b`) [E0502]
19191919
/// ```
1920+
// FIXME(#100717): In the return value, the first three strings can contain untranslated text.
19201921
pub(crate) fn describe_place_for_conflicting_borrow(
19211922
&self,
19221923
first_borrowed_place: Place<'tcx>,

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::session_diagnostics::{
55
CaptureVarKind, CaptureVarPathUseCause, OnClosureNote,
66
};
77
use itertools::Itertools;
8-
use rustc_errors::{Applicability, DiagnosticBuilder};
8+
use rustc_errors::{Applicability, DiagnosticArgValue, DiagnosticBuilder, IntoDiagnosticArg};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{CtorKind, Namespace};
1111
use rustc_hir::CoroutineKind;
@@ -48,7 +48,7 @@ mod region_errors;
4848

4949
pub(crate) use bound_region_errors::{ToUniverseInfo, UniverseInfo};
5050
pub(crate) use move_errors::{IllegalMoveOriginKind, MoveError};
51-
pub(crate) use mutability_errors::AccessKind;
51+
pub(crate) use mutability_errors::{AccessKind, PlaceAndReason};
5252
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
5353
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
5454
pub(crate) use region_name::{RegionName, RegionNameSource};
@@ -64,6 +64,18 @@ pub(super) struct DescribePlaceOpt {
6464

6565
pub(super) struct IncludingTupleField(pub(super) bool);
6666

67+
#[derive(Debug)]
68+
pub(super) struct DescribedPlace(pub(super) Option<String>);
69+
70+
impl IntoDiagnosticArg for DescribedPlace {
71+
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
72+
match self.0 {
73+
Some(descr) => descr.into_diagnostic_arg(),
74+
None => "value".into_diagnostic_arg(),
75+
}
76+
}
77+
}
78+
6779
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
6880
/// Adds a suggestion when a closure is invoked twice with a moved variable or when a closure
6981
/// is moved after being invoked.
@@ -175,6 +187,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
175187
}
176188
}
177189

190+
pub(super) fn describe_place_typed(&self, place_ref: PlaceRef<'tcx>) -> DescribedPlace {
191+
DescribedPlace(self.describe_place(place_ref))
192+
}
193+
178194
/// End-user visible description of `place` if one can be found.
179195
/// If the place is a temporary for instance, `None` will be returned.
180196
pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> {
@@ -699,6 +715,7 @@ impl UseSpans<'_> {
699715
}
700716
}
701717

718+
#[derive(Clone, Copy, Debug)]
702719
pub(super) enum BorrowedContentSource<'tcx> {
703720
DerefRawPointer,
704721
DerefMutableRef,
@@ -750,7 +767,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
750767
_ => None,
751768
})
752769
.unwrap_or_else(|| format!("dereference of `{ty}`")),
753-
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{ty}`"),
770+
BorrowedContentSource::OverloadedIndex(ty) => format!("`{ty}`"),
754771
}
755772
}
756773

‎compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
1010
use crate::diagnostics::CapturedMessageOpt;
1111
use crate::diagnostics::{DescribePlaceOpt, UseSpans};
1212
use crate::prefixes::PrefixSet;
13+
use crate::session_diagnostics::AddMoveErr;
1314
use crate::MirBorrowckCtxt;
1415

1516
#[derive(Debug)]
@@ -584,9 +585,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
584585
let binding_span = bind_to.source_info.span;
585586

586587
if j == 0 {
587-
err.span_label(binding_span, "data moved here");
588+
err.subdiagnostic(self.dcx(), AddMoveErr::Here { binding_span });
588589
} else {
589-
err.span_label(binding_span, "...and here");
590+
err.subdiagnostic(self.dcx(), AddMoveErr::AndHere { binding_span });
590591
}
591592

592593
if binds_to.len() == 1 {
@@ -604,10 +605,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
604605
}
605606

606607
if binds_to.len() > 1 {
607-
err.note(
608-
"move occurs because these variables have types that don't implement the `Copy` \
609-
trait",
610-
);
608+
err.subdiagnostic(self.dcx(), AddMoveErr::MovedNotCopy);
611609
}
612610
}
613611

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 85 additions & 89 deletions
Large diffs are not rendered by default.

‎compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,13 @@ impl OutlivesSuggestionBuilder {
173173
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name)
174174
&& !matches!(outlived_fr_name.source, RegionNameSource::Static)
175175
{
176-
diag.help(format!(
177-
"consider adding the following bound: `{fr_name}: {outlived_fr_name}`",
178-
));
176+
diag.subdiagnostic(
177+
diag.dcx,
178+
crate::session_diagnostics::OnLifetimeBound::Add {
179+
fr_name: &fr_name,
180+
outlived_fr_name: &outlived_fr_name,
181+
},
182+
);
179183
}
180184
}
181185

‎compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
797797
},
798798
_ => LifetimeReturnCategoryErr::ShortReturn {
799799
span: *span,
800-
category_desc: category.description(),
800+
category: category.description(),
801801
free_region_name: &fr_name,
802802
outlived_fr_name,
803803
},

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
1414
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1515
use rustc_span::{Span, DUMMY_SP};
1616

17+
use crate::session_diagnostics::RegionNameLabels;
1718
use crate::{universal_regions::DefiningTy, MirBorrowckCtxt};
1819

1920
/// A name for a particular region used in emitting diagnostics. This name could be a generated
@@ -137,15 +138,18 @@ impl RegionName {
137138
RegionNameHighlight::MatchedAdtAndSegment(span),
138139
_,
139140
) => {
140-
diag.span_label(*span, format!("let's call this `{self}`"));
141+
diag.subdiagnostic(
142+
diag.dcx,
143+
RegionNameLabels::NameRegion { span: *span, rg_name: self },
144+
);
141145
}
142146
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::Occluded(
143147
span,
144148
type_name,
145149
)) => {
146-
diag.span_label(
147-
*span,
148-
format!("lifetime `{self}` appears in the type {type_name}"),
150+
diag.subdiagnostic(
151+
diag.dcx,
152+
RegionNameLabels::LifetimeInType { span: *span, type_name, rg_name: self },
149153
);
150154
}
151155
RegionNameSource::AnonRegionFromOutput(
@@ -160,9 +164,9 @@ impl RegionName {
160164
);
161165
}
162166
RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => {
163-
diag.span_label(
164-
*span,
165-
format!("lifetime `{self}` appears in the type of `{upvar_name}`"),
167+
diag.subdiagnostic(
168+
diag.dcx,
169+
RegionNameLabels::LifetimeInTypeOf { span: *span, upvar_name, rg_name: self },
166170
);
167171
}
168172
RegionNameSource::AnonRegionFromOutput(
@@ -172,12 +176,19 @@ impl RegionName {
172176
diag.span_label(*span, format!("return type{mir_description} is {type_name}"));
173177
}
174178
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
175-
diag.span_label(*span, format!("yield type is {type_name}"));
179+
diag.subdiagnostic(
180+
diag.dcx,
181+
RegionNameLabels::YieldTypeIsTpye { span: *span, type_name },
182+
);
176183
}
177184
RegionNameSource::AnonRegionFromImplSignature(span, location) => {
178-
diag.span_label(
179-
*span,
180-
format!("lifetime `{self}` appears in the `impl`'s {location}"),
185+
diag.subdiagnostic(
186+
diag.dcx,
187+
RegionNameLabels::LifetimeInImpl {
188+
span: *span,
189+
rg_name: self,
190+
location: &location,
191+
},
181192
);
182193
}
183194
RegionNameSource::Static => {}

‎compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 601 additions & 3 deletions
Large diffs are not rendered by default.

‎compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use rustc_span::Symbol;
3232
use std::iter;
3333

3434
use crate::renumber::RegionCtxt;
35+
use crate::session_diagnostics::DefiningTypeNote;
3536
use crate::BorrowckInferCtxt;
3637

3738
#[derive(Debug)]
@@ -352,11 +353,13 @@ impl<'tcx> UniversalRegions<'tcx> {
352353
.map(|arg| arg.to_string())
353354
.collect::<Vec<_>>()
354355
);
355-
err.note(format!(
356-
"defining type: {} with closure args [\n {},\n]",
357-
tcx.def_path_str_with_args(def_id, args),
358-
v.join(",\n "),
359-
));
356+
err.subdiagnostic(
357+
tcx.dcx(),
358+
DefiningTypeNote::Closure {
359+
type_name: &tcx.def_path_str_with_args(def_id, args),
360+
subsets: &v.join(",\n "),
361+
},
362+
);
360363

361364
// FIXME: It'd be nice to print the late-bound regions
362365
// here, but unfortunately these wind up stored into
@@ -377,11 +380,13 @@ impl<'tcx> UniversalRegions<'tcx> {
377380
.map(|arg| arg.to_string())
378381
.collect::<Vec<_>>()
379382
);
380-
err.note(format!(
381-
"defining type: {} with coroutine args [\n {},\n]",
382-
tcx.def_path_str_with_args(def_id, args),
383-
v.join(",\n "),
384-
));
383+
err.subdiagnostic(
384+
tcx.dcx(),
385+
DefiningTypeNote::Generator {
386+
type_name: &tcx.def_path_str_with_args(def_id, &args),
387+
subsets: &v.join(",\n "),
388+
},
389+
);
385390

386391
// FIXME: As above, we'd like to print out the region
387392
// `r` but doing so is not stable across architectures
@@ -391,19 +396,28 @@ impl<'tcx> UniversalRegions<'tcx> {
391396
});
392397
}
393398
DefiningTy::FnDef(def_id, args) => {
394-
err.note(format!("defining type: {}", tcx.def_path_str_with_args(def_id, args),));
399+
err.subdiagnostic(
400+
tcx.dcx(),
401+
DefiningTypeNote::FnDef {
402+
type_name: &tcx.def_path_str_with_args(def_id, &args),
403+
},
404+
);
395405
}
396406
DefiningTy::Const(def_id, args) => {
397-
err.note(format!(
398-
"defining constant type: {}",
399-
tcx.def_path_str_with_args(def_id, args),
400-
));
407+
err.subdiagnostic(
408+
tcx.dcx(),
409+
DefiningTypeNote::Const {
410+
type_name: &tcx.def_path_str_with_args(def_id, &args),
411+
},
412+
);
401413
}
402414
DefiningTy::InlineConst(def_id, args) => {
403-
err.note(format!(
404-
"defining inline constant type: {}",
405-
tcx.def_path_str_with_args(def_id, args),
406-
));
415+
err.subdiagnostic(
416+
tcx.dcx(),
417+
DefiningTypeNote::InlineConst {
418+
type_name: &tcx.def_path_str_with_args(def_id, &args),
419+
},
420+
);
407421
}
408422
}
409423
}

0 commit comments

Comments
 (0)
Please sign in to comment.