Skip to content

Commit d83b142

Browse files
Auto merge of #149137 - JonathanBrouwer:link_section_targets2_crater, r=<try>
Crater for #148756
2 parents 683dd08 + 722cb35 commit d83b142

File tree

8 files changed

+151
-81
lines changed

8 files changed

+151
-81
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
6161
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
6262
Allow(Target::Fn),
6363
Allow(Target::Method(MethodKind::Inherent)),
64-
Allow(Target::Method(MethodKind::Trait { body: false })),
6564
Allow(Target::Method(MethodKind::Trait { body: true })),
6665
Allow(Target::Method(MethodKind::TraitImpl)),
6766
]);

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
5757
Allow(Target::Fn),
5858
Allow(Target::Method(MethodKind::Trait { body: true })),
5959
Allow(Target::Method(MethodKind::TraitImpl)),
60-
Allow(Target::Method(MethodKind::Trait { body: false })),
60+
Error(Target::Method(MethodKind::Trait { body: false })),
6161
Allow(Target::Method(MethodKind::Inherent)),
6262
Allow(Target::ForeignFn),
6363
Allow(Target::Closure),
@@ -343,7 +343,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
343343
Allow(Target::Method(MethodKind::Inherent)),
344344
Allow(Target::Method(MethodKind::Trait { body: true })),
345345
Allow(Target::Method(MethodKind::TraitImpl)),
346-
Allow(Target::Method(MethodKind::Trait { body: false })),
346+
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[track_caller]` is inherited from trait methods
347347
Allow(Target::ForeignFn),
348348
Allow(Target::Closure),
349349
Warn(Target::MacroDef),

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
470470
Allow(Target::Static),
471471
Allow(Target::Fn),
472472
Allow(Target::Method(MethodKind::Inherent)),
473-
Allow(Target::Method(MethodKind::Trait { body: false })),
474473
Allow(Target::Method(MethodKind::Trait { body: true })),
475474
Allow(Target::Method(MethodKind::TraitImpl)),
475+
Error(Target::Method(MethodKind::Trait { body: false })),
476476
]);
477477
const TEMPLATE: AttributeTemplate = template!(
478478
NameValueStr: "name",
@@ -588,12 +588,12 @@ impl<S: Stage> SingleAttributeParser<S> for LinkageParser {
588588
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
589589
Allow(Target::Fn),
590590
Allow(Target::Method(MethodKind::Inherent)),
591-
Allow(Target::Method(MethodKind::Trait { body: false })),
592591
Allow(Target::Method(MethodKind::Trait { body: true })),
593592
Allow(Target::Method(MethodKind::TraitImpl)),
594593
Allow(Target::Static),
595594
Allow(Target::ForeignStatic),
596595
Allow(Target::ForeignFn),
596+
Error(Target::Method(MethodKind::Trait { body: false })), // Not inherited
597597
]);
598598

599599
const TEMPLATE: AttributeTemplate = template!(NameValueStr: [

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<S: Stage> AttributeParser<S> for AlignParser {
322322
Allow(Target::Method(MethodKind::Inherent)),
323323
Allow(Target::Method(MethodKind::Trait { body: true })),
324324
Allow(Target::Method(MethodKind::TraitImpl)),
325-
Allow(Target::Method(MethodKind::Trait { body: false })),
325+
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[align]` is inherited from trait methods
326326
Allow(Target::ForeignFn),
327327
]);
328328

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![deny(unused_attributes)]
2+
#![feature(linkage)]
3+
#![feature(fn_align)]
4+
5+
trait Test {
6+
#[cold]
7+
//~^ ERROR cannot be used on required trait methods [unused_attributes]
8+
//~| WARN previously accepted
9+
fn method1(&self);
10+
#[link_section = ".text"]
11+
//~^ ERROR cannot be used on required trait methods [unused_attributes]
12+
//~| WARN previously accepted
13+
fn method2(&self);
14+
#[linkage = "common"]
15+
//~^ ERROR cannot be used on required trait methods [unused_attributes]
16+
//~| WARN previously accepted
17+
fn method3(&self);
18+
#[track_caller]
19+
fn method4(&self);
20+
#[rustc_align(1)]
21+
fn method5(&self);
22+
}
23+
24+
fn main() {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error: `#[cold]` attribute cannot be used on required trait methods
2+
--> $DIR/codegen_attr_on_required_trait_method.rs:6:5
3+
|
4+
LL | #[cold]
5+
| ^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= help: `#[cold]` can be applied to closures, foreign functions, functions, inherent methods, provided trait methods, and trait methods in impl blocks
9+
note: the lint level is defined here
10+
--> $DIR/codegen_attr_on_required_trait_method.rs:1:9
11+
|
12+
LL | #![deny(unused_attributes)]
13+
| ^^^^^^^^^^^^^^^^^
14+
15+
error: `#[link_section]` attribute cannot be used on required trait methods
16+
--> $DIR/codegen_attr_on_required_trait_method.rs:10:5
17+
|
18+
LL | #[link_section = ".text"]
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22+
= help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
23+
24+
error: `#[linkage]` attribute cannot be used on required trait methods
25+
--> $DIR/codegen_attr_on_required_trait_method.rs:14:5
26+
|
27+
LL | #[linkage = "common"]
28+
| ^^^^^^^^^^^^^^^^^^^^^
29+
|
30+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31+
= help: `#[linkage]` can be applied to foreign functions, foreign statics, functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
32+
33+
error: aborting due to 3 previous errors
34+

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ mod link_section {
713713
//~| HELP remove the attribute
714714
trait Tr {
715715
#[link_section = "1800"]
716+
//~^ WARN attribute cannot be used on
717+
//~| WARN previously accepted
718+
//~| HELP can be applied to
719+
//~| HELP remove the attribute
716720
fn inside_tr_no_default(&self);
717721

718722
#[link_section = "1800"]

0 commit comments

Comments
 (0)