Change:
I tried this code: I expected to see this happen: compilation failure because of attribute on an item where it makes no sense Instead, this happened: compiled successfully : cc see for where to fix this issue <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
claim

Discussion:
.warn = {-passes_previously_accepted} .label = not a function or static <ins> passes_linkage = attribute should be applied to a function or static .label = not a function definition or static </ins> passes_macro_export = `#[macro_export]` only has an effect on macro definitions

[sym::coroutine, ..] => { self.check_coroutine(attr, target); } <ins> [sym::linkage, ..] => self.check_linkage(attr, span, target), </ins> [ // ok sym::allow

| sym::cfi_encoding // FIXME(cfi_encoding) | sym::may_dangle // FIXME(dropck_eyepatch) | sym::pointee // FIXME(derive_smart_pointer) <del> | sym::linkage // FIXME(linkage) </del> | sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section) | sym::used // handled elsewhere to restrict to static items | sym::repr // handled elsewhere to restrict to type decls items

} } } <ins> fn check_linkage(&self, attr: &Attribute, span: Span, target: Target) { match target { Target::Fn | Target::Method(..) | Target::Static | Target::ForeignStatic | Target::ForeignFn => {} _ => { self.dcx().emit_err(errors::Linkage { attr_span: attr.span, span }); } } } </ins> } impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {

} #[derive(Diagnostic)] <ins> #[diag(passes_linkage)] pub struct Linkage { #[primary_span] pub attr_span: Span, #[label] pub span: Span, } #[derive(Diagnostic)] </ins> #[diag(passes_empty_confusables)] pub(crate) struct EmptyConfusables { #[primary_span]

<ins> #![feature(linkage)] #![feature(stmt_expr_attributes)] #![deny(unused_attributes)] #![allow(dead_code)] #[linkage = "weak"] //~ ERROR attribute should be applied to a function or static type InvalidTy = (); #[linkage = "weak"] //~ ERROR attribute should be applied to a function or static mod invalid_module {} #[linkage = "weak"] //~ ERROR attribute should be applied to a function or static struct F; #[linkage = "weak"] //~ ERROR attribute should be applied to a function or static impl F { #[linkage = "weak"] fn valid(&self) {} } #[linkage = "weak"] fn f() { #[linkage = "weak"] { 1 }; //~^^^^ ERROR attribute should be applied to a function or static } extern "C" { #[linkage = "weak"] static A: *const (); #[linkage = "weak"] fn bar(); } fn main() { let _ = #[linkage = "weak"] (|| 1); //~^^ ERROR attribute should be applied to a function or static } </ins>

<ins> error: attribute should be applied to a function or static --> $DIR/linkage.rs:6:1 | LL | #[linkage = "weak"] | ^^^^^^^^^^^^^^^^^^^ LL | type InvalidTy = (); | -------------------- not a function definition or static error: attribute should be applied to a function or static --> $DIR/linkage.rs:9:1 | LL | #[linkage = "weak"] | ^^^^^^^^^^^^^^^^^^^ LL | mod invalid_module {} | --------------------- not a function definition or static error: attribute should be applied to a function or static --> $DIR/linkage.rs:12:1 | LL | #[linkage = "weak"] | ^^^^^^^^^^^^^^^^^^^ LL | struct F; | --------- not a function definition or static error: attribute should be applied to a function or static --> $DIR/linkage.rs:15:1 | LL |   #[linkage = "weak"] |   ^^^^^^^^^^^^^^^^^^^ LL | / impl F { LL | |     #[linkage = "weak"] LL | |     fn valid(&self) {} LL | | } | |_- not a function definition or static error: attribute should be applied to a function or static --> $DIR/linkage.rs:23:5 | LL |       #[linkage = "weak"] |       ^^^^^^^^^^^^^^^^^^^ LL | /     { LL | |         1 LL | |     }; | |_____- not a function definition or static error: attribute should be applied to a function or static --> $DIR/linkage.rs:39:13 | LL |     let _ = #[linkage = "weak"] |             ^^^^^^^^^^^^^^^^^^^ LL |     (|| 1); |     ------ not a function definition or static error: aborting due to 6 previous errors </ins>