Skip to content

Commit f99b510

Browse files
Rollup merge of rust-lang#120488 - nnethercote:diag-lifetimes, r=oli-obk
Diagnostic lifetimes cleanups Some diagnostic simplifications. r? `@oli-obk`
2 parents 63a8885 + 514a5d8 commit f99b510

File tree

39 files changed

+144
-150
lines changed

39 files changed

+144
-150
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Display for RegionName {
188188
}
189189

190190
impl rustc_errors::IntoDiagnosticArg for RegionName {
191-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
191+
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
192192
self.to_string().into_diagnostic_arg()
193193
}
194194
}

compiler/rustc_codegen_gcc/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) enum PossibleFeature<'a> {
3535
struct ExitCode(Option<i32>);
3636

3737
impl IntoDiagnosticArg for ExitCode {
38-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
38+
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
3939
let ExitCode(exit_code) = self;
4040
match exit_code {
4141
Some(t) => t.into_diagnostic_arg(),

compiler/rustc_codegen_ssa/src/assert_module_sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl fmt::Display for CguReuse {
206206
}
207207

208208
impl IntoDiagnosticArg for CguReuse {
209-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
209+
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
210210
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
211211
}
212212
}

compiler/rustc_codegen_ssa/src/back/write.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ use rustc_data_structures::memmap::Mmap;
1414
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
1515
use rustc_data_structures::sync::Lrc;
1616
use rustc_errors::emitter::Emitter;
17-
use rustc_errors::{translation::Translate, DiagCtxt, FatalError, Level};
18-
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, ErrCode, Style};
17+
use rustc_errors::translation::Translate;
18+
use rustc_errors::{
19+
DiagCtxt, DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, ErrCode,
20+
FatalError, FluentBundle, Level, Style,
21+
};
1922
use rustc_fs_util::link_or_copy;
2023
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2124
use rustc_incremental::{
@@ -995,11 +998,9 @@ pub(crate) enum Message<B: WriteBackendMethods> {
995998
/// process another codegen unit.
996999
pub struct CguMessage;
9971000

998-
type DiagnosticArgName<'source> = Cow<'source, str>;
999-
10001001
struct Diagnostic {
10011002
msgs: Vec<(DiagnosticMessage, Style)>,
1002-
args: FxHashMap<DiagnosticArgName<'static>, rustc_errors::DiagnosticArgValue<'static>>,
1003+
args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>,
10031004
code: Option<ErrCode>,
10041005
lvl: Level,
10051006
}
@@ -1800,18 +1801,18 @@ impl SharedEmitter {
18001801
}
18011802

18021803
impl Translate for SharedEmitter {
1803-
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
1804+
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
18041805
None
18051806
}
18061807

1807-
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
1808+
fn fallback_fluent_bundle(&self) -> &FluentBundle {
18081809
panic!("shared emitter attempted to translate a diagnostic");
18091810
}
18101811
}
18111812

18121813
impl Emitter for SharedEmitter {
18131814
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
1814-
let args: FxHashMap<Cow<'_, str>, rustc_errors::DiagnosticArgValue<'_>> =
1815+
let args: FxHashMap<Cow<'_, str>, DiagnosticArgValue> =
18151816
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
18161817
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
18171818
msgs: diag.messages.clone(),

compiler/rustc_codegen_ssa/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> CopyPath<'a> {
147147
struct DebugArgPath<'a>(pub &'a Path);
148148

149149
impl IntoDiagnosticArg for DebugArgPath<'_> {
150-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
150+
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
151151
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
152152
}
153153
}
@@ -974,7 +974,7 @@ pub enum ExpectedPointerMutability {
974974
}
975975

976976
impl IntoDiagnosticArg for ExpectedPointerMutability {
977-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
977+
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
978978
match self {
979979
ExpectedPointerMutability::Mut => DiagnosticArgValue::Str(Cow::Borrowed("*mut")),
980980
ExpectedPointerMutability::Not => DiagnosticArgValue::Str(Cow::Borrowed("*_")),

compiler/rustc_const_eval/src/const_eval/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl MachineStopType for ConstEvalErrKind {
3434
}
3535
fn add_args(
3636
self: Box<Self>,
37-
adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue<'static>),
37+
adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue),
3838
) {
3939
use ConstEvalErrKind::*;
4040
match *self {

compiler/rustc_const_eval/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ impl ReportErrorExt for ResourceExhaustionInfo {
906906
}
907907

908908
impl rustc_errors::IntoDiagnosticArg for InternKind {
909-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
909+
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
910910
DiagnosticArgValue::Str(Cow::Borrowed(match self {
911911
InternKind::Static(Mutability::Not) => "static",
912912
InternKind::Static(Mutability::Mut) => "static_mut",

compiler/rustc_errors/src/diagnostic.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,36 @@ pub struct SuggestionsDisabled;
2323
/// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of
2424
/// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of
2525
/// diagnostic emission.
26-
pub type DiagnosticArg<'iter, 'source> =
27-
(&'iter DiagnosticArgName<'source>, &'iter DiagnosticArgValue<'source>);
26+
pub type DiagnosticArg<'iter> = (&'iter DiagnosticArgName, &'iter DiagnosticArgValue);
2827

2928
/// Name of a diagnostic argument.
30-
pub type DiagnosticArgName<'source> = Cow<'source, str>;
29+
pub type DiagnosticArgName = Cow<'static, str>;
3130

3231
/// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted
3332
/// to a `FluentValue` by the emitter to be used in diagnostic translation.
3433
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
35-
pub enum DiagnosticArgValue<'source> {
36-
Str(Cow<'source, str>),
34+
pub enum DiagnosticArgValue {
35+
Str(Cow<'static, str>),
3736
Number(i128),
38-
StrListSepByAnd(Vec<Cow<'source, str>>),
37+
StrListSepByAnd(Vec<Cow<'static, str>>),
3938
}
4039

4140
/// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic`
4241
/// struct). Implemented as a custom trait rather than `From` so that it is implemented on the type
4342
/// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*`
4443
/// crates to implement this.
4544
pub trait IntoDiagnosticArg {
46-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
45+
fn into_diagnostic_arg(self) -> DiagnosticArgValue;
4746
}
4847

49-
impl<'source> IntoDiagnosticArg for DiagnosticArgValue<'source> {
50-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
51-
match self {
52-
DiagnosticArgValue::Str(s) => DiagnosticArgValue::Str(Cow::Owned(s.into_owned())),
53-
DiagnosticArgValue::Number(n) => DiagnosticArgValue::Number(n),
54-
DiagnosticArgValue::StrListSepByAnd(l) => DiagnosticArgValue::StrListSepByAnd(
55-
l.into_iter().map(|s| Cow::Owned(s.into_owned())).collect(),
56-
),
57-
}
48+
impl IntoDiagnosticArg for DiagnosticArgValue {
49+
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
50+
self
5851
}
5952
}
6053

61-
impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
62-
fn into(self) -> FluentValue<'source> {
54+
impl Into<FluentValue<'static>> for DiagnosticArgValue {
55+
fn into(self) -> FluentValue<'static> {
6356
match self {
6457
DiagnosticArgValue::Str(s) => From::from(s),
6558
DiagnosticArgValue::Number(n) => From::from(n),
@@ -109,7 +102,7 @@ pub struct Diagnostic {
109102
pub span: MultiSpan,
110103
pub children: Vec<SubDiagnostic>,
111104
pub suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
112-
args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue<'static>>,
105+
args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>,
113106

114107
/// This is not used for highlighting or rendering any error message. Rather, it can be used
115108
/// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
@@ -916,7 +909,7 @@ impl Diagnostic {
916909
// Exact iteration order of diagnostic arguments shouldn't make a difference to output because
917910
// they're only used in interpolation.
918911
#[allow(rustc::potential_query_instability)]
919-
pub fn args(&self) -> impl Iterator<Item = DiagnosticArg<'_, 'static>> {
912+
pub fn args(&self) -> impl Iterator<Item = DiagnosticArg<'_>> {
920913
self.args.iter()
921914
}
922915

@@ -929,10 +922,7 @@ impl Diagnostic {
929922
self
930923
}
931924

932-
pub fn replace_args(
933-
&mut self,
934-
args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue<'static>>,
935-
) {
925+
pub fn replace_args(&mut self, args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>) {
936926
self.args = args;
937927
}
938928

@@ -990,7 +980,7 @@ impl Diagnostic {
990980
) -> (
991981
&Level,
992982
&[(DiagnosticMessage, Style)],
993-
Vec<(&Cow<'static, str>, &DiagnosticArgValue<'static>)>,
983+
Vec<(&Cow<'static, str>, &DiagnosticArgValue)>,
994984
&Option<ErrCode>,
995985
&Option<IsLint>,
996986
&MultiSpan,

0 commit comments

Comments
 (0)