2022-08-27 04:24:13 +00:00
|
|
|
//! Errors emitted by symbol_mangling.
|
|
|
|
|
2023-10-17 04:12:21 +00:00
|
|
|
use std::fmt;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2024-06-18 10:35:56 +00:00
|
|
|
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level};
|
2022-08-27 04:24:13 +00:00
|
|
|
use rustc_span::Span;
|
|
|
|
|
2022-09-13 20:19:32 +00:00
|
|
|
pub struct TestOutput {
|
2022-08-27 04:24:13 +00:00
|
|
|
pub span: Span,
|
2022-09-13 20:19:32 +00:00
|
|
|
pub kind: Kind,
|
|
|
|
pub content: String,
|
2022-08-27 04:24:13 +00:00
|
|
|
}
|
2022-08-21 04:38:23 +00:00
|
|
|
|
2023-10-17 04:12:21 +00:00
|
|
|
// 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.
|
2024-03-06 00:02:56 +00:00
|
|
|
impl<G: EmissionGuarantee> Diagnostic<'_, G> for TestOutput {
|
2024-06-18 10:35:56 +00:00
|
|
|
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
|
2023-10-17 04:12:21 +00:00
|
|
|
let TestOutput { span, kind, content } = self;
|
|
|
|
|
|
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, format!("{kind}({content})")).with_span(span)
|
2023-10-17 04:12:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 20:19:32 +00:00
|
|
|
pub enum Kind {
|
|
|
|
SymbolName,
|
|
|
|
Demangling,
|
|
|
|
DemanglingAlt,
|
|
|
|
DefPath,
|
2022-08-21 04:38:23 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 04:12:21 +00:00
|
|
|
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"),
|
2022-09-13 20:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-21 04:51:33 +00:00
|
|
|
}
|