diff options
| author | Charles Lew <crlf0710@gmail.com> | 2022-10-22 18:48:20 +0800 |
|---|---|---|
| committer | Charles Lew <crlf0710@gmail.com> | 2022-10-24 17:02:31 +0800 |
| commit | 113e8dfb7293cc070214b42541781b2eeac25ae1 (patch) | |
| tree | c12cf2c41c2492e556f72584a00e492783cdc5b3 /compiler/rustc_errors/src | |
| parent | 56f132565eb31eeb9ec7e1800a6ab2ca354e710e (diff) | |
| download | rust-113e8dfb7293cc070214b42541781b2eeac25ae1.tar.gz rust-113e8dfb7293cc070214b42541781b2eeac25ae1.zip | |
Port `dead_code` lints to be translatable.
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 32 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 2 |
2 files changed, 33 insertions, 1 deletions
diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 7640b2919f7..f6fe9192b45 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -11,6 +11,7 @@ use rustc_target::abi::TargetDataLayoutErrors; use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple}; use std::borrow::Cow; use std::fmt; +use std::fmt::Write; use std::num::ParseIntError; use std::path::{Path, PathBuf}; @@ -170,6 +171,37 @@ impl IntoDiagnosticArg for Level { } } +#[derive(Clone)] +pub struct DiagnosticSymbolList(Vec<Symbol>); + +impl From<Vec<Symbol>> for DiagnosticSymbolList { + fn from(v: Vec<Symbol>) -> Self { + DiagnosticSymbolList(v) + } +} + +impl IntoDiagnosticArg for DiagnosticSymbolList { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + // FIXME: replace the logic here with a real list formatter + let symbols = match &self.0[..] { + [symbol] => format!("`{symbol}`"), + [symbol, last] => { + format!("`{symbol}` and `{last}`",) + } + [symbols @ .., last] => { + let mut result = String::new(); + for symbol in symbols { + write!(result, "`{symbol}`, ").unwrap(); + } + write!(result, "and `{last}`").unwrap(); + result + } + [] => unreachable!(), + }; + DiagnosticArgValue::Str(Cow::Owned(symbols)) + } +} + impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { let mut diag; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 0963ea71f80..2c8a70981bc 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -376,7 +376,7 @@ pub use diagnostic::{ DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic, }; pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, Noted}; -pub use diagnostic_impls::DiagnosticArgFromDisplay; +pub use diagnostic_impls::{DiagnosticArgFromDisplay, DiagnosticSymbolList}; use std::backtrace::Backtrace; /// A handler deals with errors and other compiler output. |
