Port dead_code lints to be translatable.

This commit is contained in:
Charles Lew 2022-10-22 18:48:20 +08:00
parent 56f132565e
commit 113e8dfb72
11 changed files with 236 additions and 99 deletions

View file

@ -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;