Skip to content

Comments

[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
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
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
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
Member Author

bjorn3 commented Feb 19, 2026

Should have done r? @ghost

@bjorn3
Copy link
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
Contributor

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

@bjorn3
Copy link
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.

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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

4 participants