Skip to content

Commit e3aadff

Browse files
authored
Merge pull request #1896 from ehuss/link_name
Update `link_name` to use the attribute template
2 parents 4aa2c85 + b42bcdb commit e3aadff

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/attributes/derive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ r[attributes.derive.automatically_derived.duplicates]
9696
Duplicate instances of the `automatically_derived` attribute on the same implementation have no effect.
9797
9898
> [!NOTE]
99-
> `rustc` lints against duplicate use of this attribute.
99+
> `rustc` lints against duplicate use of this attribute on uses following the first.
100100
101101
r[attributes.derive.automatically_derived.behavior]
102102
The `automatically_derived` attribute has no behavior.

src/items/extern-crates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ r[items.extern-crate.no_link.duplicates]
104104
Duplicate instances of the `no_link` attribute are ignored.
105105
106106
> [!NOTE]
107-
> `rustc` lints against duplicate use of this attribute.
107+
> `rustc` lints against duplicate use of this attribute.
108108
109109
[identifier]: ../identifiers.md
110110
[RFC 940]: https://github.com/rust-lang/rfcs/blob/master/text/0940-hyphens-considered-harmful.md

src/items/external-blocks.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,33 @@ r[items.extern.attributes.link_name]
395395
### The `link_name` attribute
396396

397397
r[items.extern.attributes.link_name.intro]
398-
The *`link_name` attribute* may be specified on declarations inside an `extern`
399-
block to indicate the symbol to import for the given function or static.
398+
The *`link_name` [attribute][attributes]* may be applied to declarations inside an `extern` block to specify the symbol to import for the given function or static.
399+
400+
> [!EXAMPLE]
401+
> ```rust
402+
> unsafe extern "C" {
403+
> #[link_name = "actual_symbol_name"]
404+
> safe fn name_in_rust();
405+
> }
406+
> ```
400407
401408
r[items.extern.attributes.link_name.syntax]
402-
It uses the [MetaNameValueStr] syntax to specify the name of the symbol.
409+
The `link_name` attribute uses the [MetaNameValueStr] syntax.
403410
404-
```rust
405-
unsafe extern {
406-
#[link_name = "actual_symbol_name"]
407-
safe fn name_in_rust();
408-
}
409-
```
411+
r[items.extern.attributes.link_name.allowed-positions]
412+
The `link_name` attribute may only be applied to a function or static item in an `extern` block.
410413
411-
r[items.extern.attributes.link_name.exclusive]
412-
Using this attribute with the `link_ordinal` attribute will result in a
413-
compiler error.
414+
> [!NOTE]
415+
> `rustc` currently accepts and ignores the attribute in other positions but lints against it. This may become a hard error in the future.
416+
417+
r[items.extern.attributes.link_name.duplicates]
418+
Only the last instance of `link_name` on an item is used to determine the symbol name.
419+
420+
> [!NOTE]
421+
> `rustc` lints against duplicate use of this attribute on uses preceding the last. This may become a hard error in the future.
422+
423+
r[items.extern.attributes.link_name.link_ordinal]
424+
The `link_name` attribute may not be used with the [`link_ordinal`] attribute.
414425
415426
r[items.extern.attributes.link_ordinal]
416427
### The `link_ordinal` attribute
@@ -461,3 +472,4 @@ restrictions as [regular function parameters].
461472
[statics]: static-items.md
462473
[unwind-behavior]: functions.md#unwinding
463474
[value namespace]: ../names/namespaces.md
475+
[`link_ordinal`]: items.extern.attributes.link_ordinal

0 commit comments

Comments
 (0)