diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-30 15:27:16 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-30 18:46:06 +1100 |
| commit | 5350edb9e8f4e194a2cad9a41b81d97a8ed52fab (patch) | |
| tree | 6f27f6b0491a3c791c3384dc3629a9a3934432ff /compiler/rustc_errors/src/diagnostic.rs | |
| parent | fb4bca04fa1bde2f7db1b31a59e066f7bebd7fc6 (diff) | |
| download | rust-5350edb9e8f4e194a2cad9a41b81d97a8ed52fab.tar.gz rust-5350edb9e8f4e194a2cad9a41b81d97a8ed52fab.zip | |
Remove the lifetime from `DiagnosticArgValue`.
Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere.
Diffstat (limited to 'compiler/rustc_errors/src/diagnostic.rs')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 8a32e29ddc9..b3a4e1c5843 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -24,7 +24,7 @@ pub struct SuggestionsDisabled; /// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of /// diagnostic emission. pub type DiagnosticArg<'iter, 'source> = - (&'iter DiagnosticArgName<'source>, &'iter DiagnosticArgValue<'source>); + (&'iter DiagnosticArgName<'source>, &'iter DiagnosticArgValue); /// Name of a diagnostic argument. pub type DiagnosticArgName<'source> = Cow<'source, str>; @@ -32,10 +32,10 @@ pub type DiagnosticArgName<'source> = Cow<'source, str>; /// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted /// to a `FluentValue` by the emitter to be used in diagnostic translation. #[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] -pub enum DiagnosticArgValue<'source> { - Str(Cow<'source, str>), +pub enum DiagnosticArgValue { + Str(Cow<'static, str>), Number(i128), - StrListSepByAnd(Vec<Cow<'source, str>>), + StrListSepByAnd(Vec<Cow<'static, str>>), } /// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic` @@ -43,23 +43,17 @@ pub enum DiagnosticArgValue<'source> { /// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*` /// crates to implement this. pub trait IntoDiagnosticArg { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>; + fn into_diagnostic_arg(self) -> DiagnosticArgValue; } -impl<'source> IntoDiagnosticArg for DiagnosticArgValue<'source> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { - match self { - DiagnosticArgValue::Str(s) => DiagnosticArgValue::Str(Cow::Owned(s.into_owned())), - DiagnosticArgValue::Number(n) => DiagnosticArgValue::Number(n), - DiagnosticArgValue::StrListSepByAnd(l) => DiagnosticArgValue::StrListSepByAnd( - l.into_iter().map(|s| Cow::Owned(s.into_owned())).collect(), - ), - } +impl IntoDiagnosticArg for DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { + self } } -impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> { - fn into(self) -> FluentValue<'source> { +impl Into<FluentValue<'static>> for DiagnosticArgValue { + fn into(self) -> FluentValue<'static> { match self { DiagnosticArgValue::Str(s) => From::from(s), DiagnosticArgValue::Number(n) => From::from(n), @@ -109,7 +103,7 @@ pub struct Diagnostic { pub span: MultiSpan, pub children: Vec<SubDiagnostic>, pub suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>, - args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue<'static>>, + args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue>, /// This is not used for highlighting or rendering any error message. Rather, it can be used /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of @@ -931,7 +925,7 @@ impl Diagnostic { pub fn replace_args( &mut self, - args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue<'static>>, + args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue>, ) { self.args = args; } @@ -990,7 +984,7 @@ impl Diagnostic { ) -> ( &Level, &[(DiagnosticMessage, Style)], - Vec<(&Cow<'static, str>, &DiagnosticArgValue<'static>)>, + Vec<(&Cow<'static, str>, &DiagnosticArgValue)>, &Option<ErrCode>, &Option<IsLint>, &MultiSpan, |
