Skip to content

Commit 0072d0c

Browse files
authored
Rollup merge of #147418 - JonathanBrouwer:link_section_targets, r=jdonszelmann
Fix target list of `link_section` Fixes #147411 (comment) r? `@jdonszelmann` `@rustbot` beta-nominate T-compiler
2 parents 4461dd9 + 1589c6c commit 0072d0c

File tree

4 files changed

+125
-84
lines changed

4 files changed

+125
-84
lines changed

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,14 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
467467
const PATH: &[Symbol] = &[sym::link_section];
468468
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
469469
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
470-
const ALLOWED_TARGETS: AllowedTargets =
471-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Static), Allow(Target::Fn)]);
470+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
471+
Allow(Target::Static),
472+
Allow(Target::Fn),
473+
Allow(Target::Method(MethodKind::Inherent)),
474+
Allow(Target::Method(MethodKind::Trait { body: false })),
475+
Allow(Target::Method(MethodKind::Trait { body: true })),
476+
Allow(Target::Method(MethodKind::TraitImpl)),
477+
]);
472478
const TEMPLATE: AttributeTemplate = template!(
473479
NameValueStr: "name",
474480
"https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute"

tests/ui/attributes/attr-on-mac-call.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ LL | #[link_section = "x"]
8282
| ^^^^^^^^^^^^^^^^^^^^^
8383
|
8484
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
85-
= help: `#[link_section]` can be applied to statics and functions
85+
= help: `#[link_section]` can be applied to functions and statics
8686

8787
warning: `#[link_ordinal]` attribute cannot be used on macro calls
8888
--> $DIR/attr-on-mac-call.rs:33:5

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,32 @@ mod link_section {
705705
//~| WARN previously accepted
706706
//~| HELP can be applied to
707707
//~| HELP remove the attribute
708+
709+
#[link_section = "1800"]
710+
//~^ WARN attribute cannot be used on
711+
//~| WARN previously accepted
712+
//~| HELP can be applied to
713+
//~| HELP remove the attribute
714+
trait Tr {
715+
#[link_section = "1800"]
716+
fn inside_tr_no_default(&self);
717+
718+
#[link_section = "1800"]
719+
fn inside_tr_default(&self) { }
720+
}
721+
722+
impl S {
723+
#[link_section = "1800"]
724+
fn inside_abc_123(&self) { }
725+
}
726+
727+
impl Tr for S {
728+
#[link_section = "1800"]
729+
fn inside_tr_no_default(&self) { }
730+
}
731+
732+
#[link_section = "1800"]
733+
fn should_always_link() { }
708734
}
709735

710736

0 commit comments

Comments
 (0)