fix ICE in attribute name printing

This commit is contained in:
Folkert de Vries 2025-04-23 11:03:12 +02:00
parent 645d0ad2a4
commit a4630f7a86
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
4 changed files with 33 additions and 3 deletions

View file

@ -680,10 +680,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
if !other_attr.has_any_name(ALLOW_LIST) {
let path = other_attr.path();
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
let other_attr_name = path.join("::");
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
span: other_attr.span(),
naked_span: attr.span(),
attr: other_attr.name().unwrap(),
attr: other_attr_name,
});
return;

View file

@ -1249,7 +1249,7 @@ pub(crate) struct NakedFunctionIncompatibleAttribute {
pub span: Span,
#[label(passes_naked_attribute)]
pub naked_span: Span,
pub attr: Symbol,
pub attr: String,
}
#[derive(Diagnostic)]

View file

@ -51,3 +51,12 @@ fn main() {
#[unsafe(naked)] //~ ERROR should be applied to a function definition
|| {};
}
// Check that the path of an attribute without a name is printed correctly (issue #140082)
#[::a]
//~^ ERROR attribute incompatible with `#[unsafe(naked)]`
//~| ERROR failed to resolve: use of unresolved module or unlinked crate `a`
#[unsafe(naked)]
extern "C" fn issue_140082() {
naked_asm!("")
}

View file

@ -1,3 +1,9 @@
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `a`
--> $DIR/naked-invalid-attr.rs:56:5
|
LL | #[::a]
| ^ use of unresolved module or unlinked crate `a`
error: attribute should be applied to a function definition
--> $DIR/naked-invalid-attr.rs:13:1
|
@ -27,6 +33,15 @@ LL | #[unsafe(naked)]
LL | || {};
| ----- not a function definition
error[E0736]: attribute incompatible with `#[unsafe(naked)]`
--> $DIR/naked-invalid-attr.rs:56:1
|
LL | #[::a]
| ^^^^^^ the `{{root}}::a` attribute is incompatible with `#[unsafe(naked)]`
...
LL | #[unsafe(naked)]
| ---------------- function marked with `#[unsafe(naked)]` here
error: attribute should be applied to a function definition
--> $DIR/naked-invalid-attr.rs:22:5
|
@ -49,5 +64,7 @@ error: attribute should be applied to a function definition
LL | #![unsafe(naked)]
| ^^^^^^^^^^^^^^^^^ cannot be applied to crates
error: aborting due to 6 previous errors
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0433, E0736.
For more information about an error, try `rustc --explain E0433`.