diff options
| author | bors <bors@rust-lang.org> | 2022-11-04 19:43:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-11-04 19:43:36 +0000 |
| commit | 09508489efc223287731fe8abbd2a81bbf7adf8e (patch) | |
| tree | 6ab0b4cf00da631b7510ff05449647bf2b43a5fe /compiler/rustc_errors | |
| parent | c2a5c3a50fc3fb6d16cd140f55f7db61cbf08a01 (diff) | |
| parent | 347c478d886acc7e1b94af83f7fa882f73e809b7 (diff) | |
| download | rust-09508489efc223287731fe8abbd2a81bbf7adf8e.tar.gz rust-09508489efc223287731fe8abbd2a81bbf7adf8e.zip | |
Auto merge of #103978 - matthiaskrgr:rollup-iym9kmg, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #103367 (Remove std's transitive dependency on cfg-if 0.1) - #103397 (Port `dead_code` lints to be translatable.) - #103681 (libtest: run all tests in their own thread, if supported by the host) - #103792 (Migrate `codegen_ssa` to diagnostics structs - [Part 2]) - #103897 (asm: Work around LLVM bug on AArch64) - #103937 (minor changes to make method lookup diagnostic code easier to read) - #103958 (Test tidy should not count untracked paths towards entries limit) - #103964 (Give a specific lint for unsafety not being inherited) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 37 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 2 |
2 files changed, 37 insertions, 2 deletions
diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 7640b2919f7..22f6fc700fa 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -11,8 +11,10 @@ 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}; +use std::process::ExitStatus; pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display); @@ -58,6 +60,7 @@ into_diagnostic_arg_using_display!( i128, u128, std::io::Error, + std::boxed::Box<dyn std::error::Error>, std::num::NonZeroU32, hir::Target, Edition, @@ -66,7 +69,8 @@ into_diagnostic_arg_using_display!( ParseIntError, StackProtector, &TargetTriple, - SplitDebuginfo + SplitDebuginfo, + ExitStatus, ); impl IntoDiagnosticArg for bool { @@ -170,6 +174,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 f390495b53d..a8fd1a17a51 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. |
