Skip to content

Add a future incompat warning for #[no_link] - #164028

Open
bjorn3 wants to merge 1 commit into
rust-lang:mainfrom
bjorn3:no_link_fcw
Open

bjorn3 wants to merge 1 commit into
rust-lang:mainfrom
bjorn3:no_link_fcw

Conversation

@bjorn3

@bjorn3 bjorn3 commented Oct 9, 2026

Copy link
Copy Markdown
Member

This is a pre-1.0 attribute that accidentally got stabilized. It was only meant for compiler plugins which we no longer support, not for regular crates. It is rather fragile and can easily lead to linker errors depending on where rustc decides to codegen functions and statics, which varies between rustc versions. It might also be unsound if a crate for example expects a global constructor it defined to run. Using it doesn't have an effect on the size of the produced binaries except when it defines a #[used] static given that we remove all unused functions and statics at link time already.

@rustbot

rustbot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 9, 2026
@rustbot

rustbot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 20 candidates

@bjorn3

bjorn3 commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

This was previously cratered in #152856 (comment). That PR entirely removed #[no_link], while this one only emits a future incompat lint.

@JonathanBrouwer JonathanBrouwer added T-lang Relevant to the language team I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 9, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

Given that the crater run only found 6 crates that this broke, I also wouldn't be against entirely removing the attribute immediately. What we want to do here is a @rust-lang/lang decision though, so lets let them decide

@rust-log-analyzer

This comment has been minimized.

@bjorn3

bjorn3 commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

I think it is polite to keep it as future incompat warning for a couple of releases.

@bjorn3

bjorn3 commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Blessed the tests and added #164032 as tracking issue.

@rust-log-analyzer

This comment has been minimized.

This is a pre-1.0 attribute that accidentally got stabilized. It was
only meant for compiler plugins which we no longer support, not for
regular crates. It is rather fragile and can easily lead to linker
errors depending on where rustc decides to codegen functions and
statics, which varies between rustc versions. It might also be unsound
if a crate for example expects a global constructor it defined to run.
Using it doesn't have an effect on the size of the produced binaries
except when it defines a `#[used]` static given that we remove all
unused functions and statics at link time already.
@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Oct 10, 2026
/// defined to run. Using it doesn't have an effect on the size of the produced
/// binaries except when it defines a `#[used]` static given that we remove all unused
/// functions and statics at link time already.
pub NO_LINK_ATTR_USED,

@traviscross traviscross Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub NO_LINK_ATTR_USED,
pub NO_LINK_ATTRIBUTES,

Per our RFC 0344 guidance on pluralization, that our existing lints spell out attributes, and that the used part is implied, I'd suggest NO_LINK_ATTRIBUTES.

View changes since the review

Comment on lines +6012 to +6016
Warn,
"detects usage of `#[no_link]` on `extern crate` items",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(FutureReleaseError #164032),
};

@traviscross traviscross Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is polite to keep it as future incompat warning for a couple of releases.

Do you want to make this a hard error after a couple of releases? If so, then it'd be better to propose this at deny-by-default and warn-in-deps (if the feeling is that this is sufficiently unused that it'd be OK to go straight to that). Otherwise, our normal practice would be, later, to first bump this to that, then to move to the hard error.

View changes since the review

@rust-bors

rust-bors Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #163235) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang S-waiting-on-t-lang Status: Awaiting decision from T-lang T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants