mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-27 19:16:36 +00:00
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
//! Errors emitted by symbol_mangling.
|
|
|
|
use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level};
|
|
use rustc_span::Span;
|
|
use std::fmt;
|
|
|
|
pub struct TestOutput {
|
|
pub span: Span,
|
|
pub kind: Kind,
|
|
pub content: String,
|
|
}
|
|
|
|
// This diagnostic doesn't need translation because (a) it doesn't contain any
|
|
// natural language, and (b) it's only used in tests. So we construct it
|
|
// manually and avoid the fluent machinery.
|
|
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TestOutput {
|
|
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
|
let TestOutput { span, kind, content } = self;
|
|
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
|
let mut diag = DiagnosticBuilder::new(dcx, level, format!("{kind}({content})"));
|
|
diag.span(span);
|
|
diag
|
|
}
|
|
}
|
|
|
|
pub enum Kind {
|
|
SymbolName,
|
|
Demangling,
|
|
DemanglingAlt,
|
|
DefPath,
|
|
}
|
|
|
|
impl fmt::Display for Kind {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Kind::SymbolName => write!(f, "symbol-name"),
|
|
Kind::Demangling => write!(f, "demangling"),
|
|
Kind::DemanglingAlt => write!(f, "demangling-alt"),
|
|
Kind::DefPath => write!(f, "def-path"),
|
|
}
|
|
}
|
|
}
|