-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Migrate symbol_mangling
module to new diagnostics structs
#100831
Changes from all commits
86f8c4e
359002b
bd83bbc
8f5fada
ef2f6ab
3ee6946
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
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}) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Errors emitted by symbol_mangling. | ||
|
||
use rustc_macros::SessionDiagnostic; | ||
use rustc_span::Span; | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(symbol_mangling::invalid_symbol_name)] | ||
pub struct InvalidSymbolName { | ||
#[primary_span] | ||
pub span: Span, | ||
pub mangled_formatted: String, | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(symbol_mangling::invalid_trait_item)] | ||
pub struct InvalidTraitItem { | ||
#[primary_span] | ||
pub span: Span, | ||
pub demangling_formatted: String, | ||
} | ||
|
||
#[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, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +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 rustc_hir::def_id::LocalDefId; | ||
use rustc_middle::ty::print::with_no_trimmed_paths; | ||
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt}; | ||
|
@@ -59,16 +60,27 @@ impl SymbolNamesTest<'_> { | |
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)), | ||
); | ||
let mangled = tcx.symbol_name(instance); | ||
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled)); | ||
tcx.sess.emit_err(InvalidSymbolName { | ||
span: attr.span, | ||
mangled_formatted: format!("{mangled}"), | ||
}); | ||
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) { | ||
tcx.sess.span_err(attr.span, &format!("demangling({})", demangling)); | ||
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling)); | ||
tcx.sess.emit_err(InvalidTraitItem { | ||
span: attr.span, | ||
demangling_formatted: format!("{demangling}"), | ||
}); | ||
tcx.sess.emit_err(AltInvalidTraitItem { | ||
span: attr.span, | ||
alt_demangling_formatted: format!("{:#}", demangling), | ||
}); | ||
Comment on lines
-64
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure where "trait item" came from, this is just the "demangling output" part of This could include e.g. |
||
} | ||
} | ||
|
||
for attr in tcx.get_attrs(def_id.to_def_id(), DEF_PATH) { | ||
let path = with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())); | ||
tcx.sess.span_err(attr.span, &format!("def-path({})", path)); | ||
tcx.sess.emit_err(InvalidDefPath { | ||
span: attr.span, | ||
def_path: with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())), | ||
}); | ||
Comment on lines
-62
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was confused why we had symbol-mangling diagnostics... and we don't. This There are no user-facing errors here, these are the Even these using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the very least, I would like to see the name of the the attribute generating this (instead of "invalid"). So e.g. this should be Ideally it would be tagged as "internal" so translators don't waste their time or get confused - there's basically no natural-language text here, the I would compare it to |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can actually be all merged together, since they're
{$kind}({$contents})
.Might even make more sense to use
{$kind} = {$contents}
or some other style, but that's a bit orthogonal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be a good way to make this go through the translation infrastructure - so that we can eventually remove the non-translation codepaths - while making translation of the message a no-op.
@JhonnyBillM do you think you could submit a new PR that makes this change? It's just that these "diagnostics" really only exist to be checked our the test suite to test the mangling scheme, and so names like they have (which I should have caught in review), might be misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review! Helped me understand better this crate and file.
Addressed your points in #101782