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

View all comments

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.

@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
Comment thread compiler/rustc_lint_defs/src/builtin.rs Outdated
Comment thread compiler/rustc_lint_defs/src/builtin.rs Outdated
@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 26, 2026
@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

❌ Commit 7433798 has been unapproved due to PR CI failure. Reapprove it with @bors r+ force if you want to ignore the failure.

@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@bjorn3

bjorn3 commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

Diagnostic formatting changed decorations in a minor way. Blessed the respective test.

@bors r=JonathanBrouwer

Details
diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr
index c6c5735b9ec..ec0a8a9d1a4 100644
--- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr
+++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr
@@ -119,7 +119,7 @@ error: the `no_link` attribute cannot be used on modules
    |
 LL | #[no_link]
    |   ^^^^^^^
-LL |
+...
 LL | mod no_link {
    |
    = help: the `no_link` attribute can only be applied to extern crates
@@ -145,7 +145,7 @@ error: the `no_link` attribute cannot be used on structs
    |
 LL |     #[no_link]
    |       ^^^^^^^
-LL |
+...
 LL |     struct S {
    |
    = help: the `no_link` attribute can only be applied to extern crates

@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b0b50b0 has been tentatively approved by JonathanBrouwer

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 26, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 26, 2026
@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

❌ Commit b0b50b0 has been unapproved due to PR CI failure. Reapprove it with @bors r+ force if you want to ignore the failure.

@rust-log-analyzer

This comment has been minimized.

@bjorn3

bjorn3 commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

lint-docs doesn't like #[cfg_attr(bootstrap, doc(test(attr(cfg(false)))))]. tidy doesn't like #[cfg_attr(bootstrap, doc = "```rust,ignore")] #[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]. What is the intended way to ignore the doctest on the bootstrap compiler?

@JonathanBrouwer

Copy link
Copy Markdown
Member

What I've seen in the past to get around tidy is to also cfg_attr the closing backticks.
Ideally we should just fix tidy tho...

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.
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b4c2489 has been tentatively approved by JonathanBrouwer

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 27, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 27, 2026
Add a future incompat warning for #[no_link]

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.
rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #159580 (Reject cfg on expressions that cannot be safely removed)
 - #162597 (raise ambiguity error on attribute macro that could be tool attribute)
 - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs)
 - #163059 (Recover invalid return type until `{`, `}` or `;`)
 - #163672 (Use runCodeGen Abstraction for new LLVM)
 - #164028 (Add a future incompat warning for #[no_link])
 - #164188 (Suggest adding lifetime for `dyn Trait` in return type)
 - #164345 (fix: handle `false` in root contexts)
 - #164494 (drop ands which are a superset of other ands)
 - #164766 (Unstably introduce MVP edition migration lint `unmarked_unchecked_type_aliases` together with bikeshed attribute `#[rustc_unchecked_type_alias]`)
 - #164785 (delegation: emit error when there is no field for `Self` mapping)
 - #164799 (Don't use `IntoIterator` in parallel API)
 - #164871 (Refactor call argument codegen)
 - #164648 (parse inline and rustc_force_inline with same parser)
 - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration)
 - #164900 (make tool_attrs method to retrieve tool attributes.)
 - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit)
 - #164996 (miri: add missing alignment check in write_bytes)
 - #165012 (Remove Span::eq_ctxt())
 - #165013 ([tiny] Add missing backticks around lifetime name)
 - #165024 (rustdoc-search: rank re-export lower)
 - #165028 (Update enzyme to fix one bug related to higher-order derivatives)

> [!WARNING]
> This rollup conflicts with pending auto build #165042 and may need to be recreated if the pending build succeeds.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 27, 2026
Add a future incompat warning for #[no_link]

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.
rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #159580 (Reject cfg on expressions that cannot be safely removed)
 - #162597 (raise ambiguity error on attribute macro that could be tool attribute)
 - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs)
 - #163059 (Recover invalid return type until `{`, `}` or `;`)
 - #163672 (Use runCodeGen Abstraction for new LLVM)
 - #164028 (Add a future incompat warning for #[no_link])
 - #164188 (Suggest adding lifetime for `dyn Trait` in return type)
 - #164345 (fix: handle `false` in root contexts)
 - #164494 (drop ands which are a superset of other ands)
 - #164785 (delegation: emit error when there is no field for `Self` mapping)
 - #164799 (Don't use `IntoIterator` in parallel API)
 - #164871 (Refactor call argument codegen)
 - #164648 (parse inline and rustc_force_inline with same parser)
 - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration)
 - #164900 (make tool_attrs method to retrieve tool attributes.)
 - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit)
 - #164996 (miri: add missing alignment check in write_bytes)
 - #165012 (Remove Span::eq_ctxt())
 - #165013 ([tiny] Add missing backticks around lifetime name)
 - #165024 (rustdoc-search: rank re-export lower)
 - #165028 (Update enzyme to fix one bug related to higher-order derivatives)
rust-bors Bot pushed a commit that referenced this pull request Oct 28, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #159580 (Reject cfg on expressions that cannot be safely removed)
 - #162597 (raise ambiguity error on attribute macro that could be tool attribute)
 - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs)
 - #163059 (Recover invalid return type until `{`, `}` or `;`)
 - #163672 (Use runCodeGen Abstraction for new LLVM)
 - #164028 (Add a future incompat warning for #[no_link])
 - #164188 (Suggest adding lifetime for `dyn Trait` in return type)
 - #164345 (fix: handle `false` in root contexts)
 - #164494 (drop ands which are a superset of other ands)
 - #164785 (delegation: emit error when there is no field for `Self` mapping)
 - #164799 (Don't use `IntoIterator` in parallel API)
 - #164871 (Refactor call argument codegen)
 - #164648 (parse inline and rustc_force_inline with same parser)
 - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration)
 - #164900 (make tool_attrs method to retrieve tool attributes.)
 - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit)
 - #164996 (miri: add missing alignment check in write_bytes)
 - #165012 (Remove Span::eq_ctxt())
 - #165013 ([tiny] Add missing backticks around lifetime name)
 - #165024 (rustdoc-search: rank re-export lower)
 - #165028 (Update enzyme to fix one bug related to higher-order derivatives)

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 (`#[…]`, `#![…]`) disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants