Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update symbol_mangling diagnostics migration #101782

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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})
44 changes: 21 additions & 23 deletions compiler/rustc_symbol_mangling/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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,
}

#[derive(SessionDiagnostic)]
#[diag(symbol_mangling::invalid_def_path)]
pub struct InvalidDefPath {
#[primary_span]
pub span: Span,
pub def_path: 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)
}
}
22 changes: 13 additions & 9 deletions compiler/rustc_symbol_mangling/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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())),
});
}
}
Expand Down