Skip to content

[DO NOT MERGE] Remove #[no_link] attribute#152856

Open
bjorn3 wants to merge 1 commit intorust-lang:mainfrom
bjorn3:remove_no_link_attr
Open

[DO NOT MERGE] Remove #[no_link] attribute#152856
bjorn3 wants to merge 1 commit intorust-lang:mainfrom
bjorn3:remove_no_link_attr

Conversation

@bjorn3
Copy link
Copy Markdown
Member

@bjorn3 bjorn3 commented Feb 19, 2026

This is a pre-1.0 attribute that accidentally got stabilized. It was meant for compiler plugins, not regular crates. #152854 (comment) It is also rather fragile. If you use any function defined inside a crate you import using #[no_link] it might or might not work depending on if another crate has a normal dependency on it, if the function is codegened cross-crate and if the call site is optimized out or not. As such I think it should be deprecated and eventually removed.

Fixes #152854

This PR is probably not something we can merge immediately, but should be enough for a crater run.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 19, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in compiler/rustc_hir/src/attrs

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-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Feb 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 19, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
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 68 candidates
  • Random selection from 15 candidates

@bjorn3 bjorn3 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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 19, 2026
@bjorn3
Copy link
Copy Markdown
Member Author

bjorn3 commented Feb 19, 2026

Should have done r? @ghost

@bjorn3
Copy link
Copy Markdown
Member Author

bjorn3 commented Feb 19, 2026

Reference changes
diff --git a/src/attributes.md b/src/attributes.md
index 696e6184..5b75095a 100644
--- a/src/attributes.md
+++ b/src/attributes.md
@@ -240,7 +240,6 @@ The following is an index of all built-in attributes.
   - [`link`] --- Specifies a native library to link with an `extern` block.
   - [`link_name`] --- Specifies the name of the symbol for functions or statics in an `extern` block.
   - [`link_ordinal`] --- Specifies the ordinal of the symbol for functions or statics in an `extern` block.
-  - [`no_link`] --- Prevents linking an extern crate.
   - [`repr`] --- Controls type layout.
   - [`crate_type`] --- Specifies the type of crate (library, executable, etc.).
   - [`no_main`] --- Disables emitting the `main` symbol.
@@ -323,7 +322,6 @@ The following is an index of all built-in attributes.
 [`naked`]: attributes/codegen.md#the-naked-attribute
 [`no_builtins`]: attributes/codegen.md#the-no_builtins-attribute
 [`no_implicit_prelude`]: names/preludes.md#the-no_implicit_prelude-attribute
-[`no_link`]: items/extern-crates.md#the-no_link-attribute
 [`no_main`]: crates-and-source-files.md#the-no_main-attribute
 [`no_mangle`]: abi.md#the-no_mangle-attribute
 [`no_std`]: names/preludes.md#the-no_std-attribute
diff --git a/src/items/extern-crates.md b/src/items/extern-crates.md
index ffad1d98..feb55409 100644
--- a/src/items/extern-crates.md
+++ b/src/items/extern-crates.md
@@ -59,40 +59,6 @@ An external crate dependency can be declared without binding its name in scope b
 r[items.extern-crate.underscore.macro_use]
 The [`macro_use` attribute] works as usual and imports the macro names into the [`macro_use` prelude].
 
-<!-- template:attributes -->
-r[items.extern-crate.no_link]
-## The `no_link` attribute
-
-r[items.extern-crate.no_link.intro]
-The *`no_link` [attribute][attributes]* may be applied to an `extern crate` item to prevent linking the crate.
-
-> [!NOTE]
-> This is helpful, e.g., when only the macros of a crate are needed.
-
-> [!EXAMPLE]
-> <!-- ignore: requires external crates -->
-> ```rust,ignore
-> #[no_link]
-> extern crate other_crate;
->
-> other_crate::some_macro!();
-> ```
-
-r[items.extern-crate.no_link.syntax]
-The `no_link` attribute uses the [MetaWord] syntax.
-
-r[items.extern-crate.no_link.allowed-positions]
-The `no_link` attribute may only be applied to an `extern crate` declaration.
-
-> [!NOTE]
-> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
-
-r[items.extern-crate.no_link.duplicates]
-Only the first use of `no_link` on an `extern crate` declaration has effect.
-
-> [!NOTE]
-> `rustc` lints against any use following the first. This may become an error in the future.
-
 [identifier]: ../identifiers.md
 [RFC 940]: https://github.com/rust-lang/rfcs/blob/master/text/0940-hyphens-considered-harmful.md
 [`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute

@apiraino
Copy link
Copy Markdown
Contributor

@bjorn3 mostly for my understanding - would this change need an MCP?

@bjorn3
Copy link
Copy Markdown
Member Author

bjorn3 commented Feb 23, 2026

I think it would need a lang FCP as this affects the language. It definitively needs a crater run if we want to go through with removing it.

@bjorn3
Copy link
Copy Markdown
Member Author

bjorn3 commented Feb 27, 2026

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Feb 27, 2026
[DO NOT MERGE] Remove #[no_link] attribute
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Feb 27, 2026

☀️ Try build successful (CI)
Build commit: 349c4bf (349c4bfa6ac87b818f6fd19d4869c0b24790ac6a, parent: 0ee5907d597b02afadb5daa26a60fedb72f098d1)

@bjorn3
Copy link
Copy Markdown
Member Author

bjorn3 commented Feb 27, 2026

@craterbot check

@craterbot
Copy link
Copy Markdown
Collaborator

👌 Experiment pr-152856 created and queued.
🤖 Automatically detected try build 349c4bf
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 27, 2026
@craterbot
Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-152856 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-152856 is completed!
📊 9 regressed and 3 fixed (830989 total)
📊 2512 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-152856/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Mar 2, 2026
@bjorn3 bjorn3 added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Mar 3, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 7, 2026

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

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 14, 2026

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

@wesleywiser wesleywiser 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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[no_link] attribute does not prevent crate linking

6 participants