diff options
| author | bors <bors@rust-lang.org> | 2022-11-09 23:19:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-11-09 23:19:55 +0000 |
| commit | 34115d040b43d9a0dcc313c6282520a86d1e6f61 (patch) | |
| tree | 13aa86008ab3c54ca9b4fc639c8ff38cf1a842a7 /compiler/rustc_errors/src | |
| parent | e75aab045fc476f176a58c408f6b06f0e275c6e1 (diff) | |
| parent | 70c04a2fd1738ece290631c53c59616c30febdf9 (diff) | |
| download | rust-34115d040b43d9a0dcc313c6282520a86d1e6f61.tar.gz rust-34115d040b43d9a0dcc313c6282520a86d1e6f61.zip | |
Auto merge of #104215 - Manishearth:rollup-5r957ad, r=Manishearth
Rollup of 9 pull requests Successful merges: - #101005 (Migrate rustc_codegen_llvm to SessionDiagnostics) - #103307 (Add context to compiler error message) - #103464 (Add support for custom mir) - #103929 (Cleanup Apple-related code in rustc_target) - #104015 (Remove linuxkernel targets) - #104020 (Limit efiapi calling convention to supported arches) - #104156 (Cleanups in autoderef impl) - #104171 (Update books) - #104184 (Fix `rustdoc --version` when used with download-rustc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 32 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 6 |
2 files changed, 38 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 45c017df918..43101bbb9d3 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -44,6 +44,15 @@ pub trait IntoDiagnosticArg { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>; } +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), + } + } +} + impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> { fn into(self) -> FluentValue<'source> { match self { @@ -205,6 +214,22 @@ impl Diagnostic { } #[track_caller] + pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self { + Diagnostic { + level, + message: messages, + code: None, + span: MultiSpan::new(), + children: vec![], + suggestions: Ok(vec![]), + args: Default::default(), + sort_span: DUMMY_SP, + is_lint: false, + emitted_at: DiagnosticLocation::caller(), + } + } + + #[track_caller] pub fn new_with_code<M: Into<DiagnosticMessage>>( level: Level, code: Option<DiagnosticId>, @@ -931,6 +956,13 @@ impl Diagnostic { self } + pub fn replace_args( + &mut self, + args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue<'static>>, + ) { + self.args = args; + } + pub fn styled_message(&self) -> &[(DiagnosticMessage, Style)] { &self.message } diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 22f6fc700fa..c6035705e39 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -107,6 +107,12 @@ impl IntoDiagnosticArg for String { } } +impl<'a> IntoDiagnosticArg for Cow<'a, str> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + DiagnosticArgValue::Str(Cow::Owned(self.into_owned())) + } +} + impl<'a> IntoDiagnosticArg for &'a Path { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { DiagnosticArgValue::Str(Cow::Owned(self.display().to_string())) |
