mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #101782 - JhonnyBillM:refactor-symbol-mangling-diags-migration, r=davidtwco
Update `symbol_mangling` diagnostics migration Addresses comments raised in #100831. r? `@eddyb` `@davidtwco`
This commit is contained in:
commit
d6534317c7
@ -1,7 +1 @@
|
||||
symbol_mangling_invalid_symbol_name = symbol-name({$mangled_formatted})
|
||||
|
||||
symbol_mangling_invalid_trait_item = demangling({$demangling_formatted})
|
||||
|
||||
symbol_mangling_alt_invalid_trait_item = demangling-alt({$alt_demangling_formatted})
|
||||
|
||||
symbol_mangling_invalid_def_path = def-path({$def_path})
|
||||
symbol_mangling_test_output = {$kind}({$content})
|
||||
|
@ -1,36 +1,34 @@
|
||||
//! Errors emitted by symbol_mangling.
|
||||
|
||||
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
use rustc_span::Span;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(symbol_mangling::invalid_symbol_name)]
|
||||
pub struct InvalidSymbolName {
|
||||
#[diag(symbol_mangling::test_output)]
|
||||
pub struct TestOutput {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub mangled_formatted: String,
|
||||
pub kind: Kind,
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(symbol_mangling::invalid_trait_item)]
|
||||
pub struct InvalidTraitItem {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub demangling_formatted: String,
|
||||
pub enum Kind {
|
||||
SymbolName,
|
||||
Demangling,
|
||||
DemanglingAlt,
|
||||
DefPath,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(symbol_mangling::alt_invalid_trait_item)]
|
||||
pub struct AltInvalidTraitItem {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub alt_demangling_formatted: String,
|
||||
impl IntoDiagnosticArg for Kind {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||
let kind = match self {
|
||||
Kind::SymbolName => "symbol-name",
|
||||
Kind::Demangling => "demangling",
|
||||
Kind::DemanglingAlt => "demangling-alt",
|
||||
Kind::DefPath => "def-path",
|
||||
}
|
||||
.into();
|
||||
DiagnosticArgValue::Str(kind)
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(symbol_mangling::invalid_def_path)]
|
||||
pub struct InvalidDefPath {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub def_path: String,
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
//! def-path. This is used for unit testing the code that generates
|
||||
//! paths etc in all kinds of annoying scenarios.
|
||||
|
||||
use crate::errors::{AltInvalidTraitItem, InvalidDefPath, InvalidSymbolName, InvalidTraitItem};
|
||||
use crate::errors::{Kind, TestOutput};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
|
||||
@ -60,26 +60,30 @@ impl SymbolNamesTest<'_> {
|
||||
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)),
|
||||
);
|
||||
let mangled = tcx.symbol_name(instance);
|
||||
tcx.sess.emit_err(InvalidSymbolName {
|
||||
tcx.sess.emit_err(TestOutput {
|
||||
span: attr.span,
|
||||
mangled_formatted: format!("{mangled}"),
|
||||
kind: Kind::SymbolName,
|
||||
content: format!("{mangled}"),
|
||||
});
|
||||
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
|
||||
tcx.sess.emit_err(InvalidTraitItem {
|
||||
tcx.sess.emit_err(TestOutput {
|
||||
span: attr.span,
|
||||
demangling_formatted: format!("{demangling}"),
|
||||
kind: Kind::Demangling,
|
||||
content: format!("{demangling}"),
|
||||
});
|
||||
tcx.sess.emit_err(AltInvalidTraitItem {
|
||||
tcx.sess.emit_err(TestOutput {
|
||||
span: attr.span,
|
||||
alt_demangling_formatted: format!("{:#}", demangling),
|
||||
kind: Kind::DemanglingAlt,
|
||||
content: format!("{:#}", demangling),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for attr in tcx.get_attrs(def_id.to_def_id(), DEF_PATH) {
|
||||
tcx.sess.emit_err(InvalidDefPath {
|
||||
tcx.sess.emit_err(TestOutput {
|
||||
span: attr.span,
|
||||
def_path: with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())),
|
||||
kind: Kind::DefPath,
|
||||
content: with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user