Skip to content
Open
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
Expand Up @@ -61,7 +61,6 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
]);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::ForeignFn),
Allow(Target::Closure),
Expand Down Expand Up @@ -343,7 +342,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[track_caller]` is inherited from trait methods
Allow(Target::ForeignFn),
Allow(Target::Closure),
Warn(Target::MacroDef),
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
Allow(Target::Static),
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
]);
Expand Down Expand Up @@ -588,12 +587,12 @@ impl<S: Stage> SingleAttributeParser<S> for LinkageParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
Allow(Target::Static),
Allow(Target::ForeignStatic),
Allow(Target::ForeignFn),
Warn(Target::Method(MethodKind::Trait { body: false })), // Not inherited
]);

const TEMPLATE: AttributeTemplate = template!(NameValueStr: [
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl<S: Stage> AttributeParser<S> for AlignParser {
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[align]` is inherited from trait methods
Allow(Target::ForeignFn),
]);

Expand Down
24 changes: 24 additions & 0 deletions tests/ui/attributes/codegen_attr_on_required_trait_method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![deny(unused_attributes)]
#![feature(linkage)]
#![feature(fn_align)]

trait Test {
#[cold]
//~^ ERROR cannot be used on required trait methods [unused_attributes]
//~| WARN previously accepted
fn method1(&self);
#[link_section = ".text"]
//~^ ERROR cannot be used on required trait methods [unused_attributes]
//~| WARN previously accepted
fn method2(&self);
#[linkage = "common"]
//~^ ERROR cannot be used on required trait methods [unused_attributes]
//~| WARN previously accepted
fn method3(&self);
#[track_caller]
fn method4(&self);
#[rustc_align(1)]
fn method5(&self);
}

fn main() {}
34 changes: 34 additions & 0 deletions tests/ui/attributes/codegen_attr_on_required_trait_method.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error: `#[cold]` attribute cannot be used on required trait methods
--> $DIR/codegen_attr_on_required_trait_method.rs:6:5
|
LL | #[cold]
| ^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[cold]` can be applied to closures, foreign functions, functions, inherent methods, provided trait methods, and trait methods in impl blocks
note: the lint level is defined here
--> $DIR/codegen_attr_on_required_trait_method.rs:1:9
|
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^

error: `#[link_section]` attribute cannot be used on required trait methods
--> $DIR/codegen_attr_on_required_trait_method.rs:10:5
|
LL | #[link_section = ".text"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks

error: `#[linkage]` attribute cannot be used on required trait methods
--> $DIR/codegen_attr_on_required_trait_method.rs:14:5
|
LL | #[linkage = "common"]
| ^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[linkage]` can be applied to foreign functions, foreign statics, functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks

error: aborting due to 3 previous errors

4 changes: 4 additions & 0 deletions tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ mod link_section {
//~| HELP remove the attribute
trait Tr {
#[link_section = "1800"]
//~^ WARN attribute cannot be used on
//~| WARN previously accepted
//~| HELP can be applied to
//~| HELP remove the attribute
fn inside_tr_no_default(&self);

#[link_section = "1800"]
Expand Down
Loading
Loading