Skip to content

Commit 4aa2c85

Browse files
authored
Merge pull request #1898 from ehuss/no_link
Update `no_link` to use the attribute template
2 parents dfaaa77 + dda1f41 commit 4aa2c85

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/items/extern-crates.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,35 @@ into the [`macro_use` prelude].
7676
r[items.extern-crate.no_link]
7777
## The `no_link` attribute
7878

79-
The *`no_link` attribute* may be specified on an `extern crate` item to
80-
prevent linking the crate into the output. This is commonly used to load a
81-
crate to access only its macros.
79+
r[items.extern-crate.no_link.intro]
80+
The *`no_link` [attribute][attributes]* may be applied to an `extern crate` item to prevent linking the crate.
81+
82+
> [!NOTE]
83+
> This is helpful, e.g., when only the macros of a crate are needed.
84+
85+
> [!EXAMPLE]
86+
> <!-- ignore: requires external crates -->
87+
> ```rust,ignore
88+
> #[no_link]
89+
> extern crate other_crate;
90+
>
91+
> other_crate::some_macro!();
92+
> ```
93+
94+
r[items.extern-crate.no_link.syntax]
95+
The `no_link` attribute uses the [MetaWord] syntax and so does not accept any arguments.
96+
97+
r[items.extern-crate.no_link.allowed-positions]
98+
The `no_link` attribute may only be applied to an `extern crate` declaration.
99+
100+
> [!NOTE]
101+
> `rustc` currently accepts and ignores the attribute in other positions but lints against it. This may become a hard error in the future.
102+
103+
r[items.extern-crate.no_link.duplicates]
104+
Duplicate instances of the `no_link` attribute are ignored.
105+
106+
> [!NOTE]
107+
> `rustc` lints against duplicate use of this attribute.
82108
83109
[identifier]: ../identifiers.md
84110
[RFC 940]: https://github.com/rust-lang/rfcs/blob/master/text/0940-hyphens-considered-harmful.md

0 commit comments

Comments
 (0)