From 08aeb897ba1a77bd2ce34d5586060b092152c31b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 15:59:54 -0700 Subject: [PATCH 1/7] Unwrap link_name --- src/items/external-blocks.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index b60cb4505..0faf9e502 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -395,8 +395,7 @@ r[items.extern.attributes.link_name] ### The `link_name` attribute r[items.extern.attributes.link_name.intro] -The *`link_name` attribute* may be specified on declarations inside an `extern` -block to indicate the symbol to import for the given function or static. +The *`link_name` attribute* may be specified on declarations inside an `extern` block to indicate the symbol to import for the given function or static. r[items.extern.attributes.link_name.syntax] It uses the [MetaNameValueStr] syntax to specify the name of the symbol. @@ -409,8 +408,7 @@ unsafe extern { ``` r[items.extern.attributes.link_name.exclusive] -Using this attribute with the `link_ordinal` attribute will result in a -compiler error. +Using this attribute with the `link_ordinal` attribute will result in a compiler error. r[items.extern.attributes.link_ordinal] ### The `link_ordinal` attribute From 3401da65ff4e2bc4492642cd152d0421518c4c2f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 16:10:33 -0700 Subject: [PATCH 2/7] Link "attribute" --- src/items/external-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 0faf9e502..03204c5be 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -395,7 +395,7 @@ r[items.extern.attributes.link_name] ### The `link_name` attribute r[items.extern.attributes.link_name.intro] -The *`link_name` attribute* may be specified on declarations inside an `extern` block to indicate the symbol to import for the given function or static. +The *`link_name` [attribute][attributes]* may be specified on declarations inside an `extern` block to indicate the symbol to import for the given function or static. r[items.extern.attributes.link_name.syntax] It uses the [MetaNameValueStr] syntax to specify the name of the symbol. From 83f6b918e87e9001cdfbdbfeec28c4fe9555f90c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 16:10:51 -0700 Subject: [PATCH 3/7] Move example to intro and example block --- src/items/external-blocks.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 03204c5be..f4d517a65 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -397,16 +397,17 @@ r[items.extern.attributes.link_name] r[items.extern.attributes.link_name.intro] The *`link_name` [attribute][attributes]* may be specified on declarations inside an `extern` block to indicate the symbol to import for the given function or static. +> [!EXAMPLE] +> ```rust +> unsafe extern { +> #[link_name = "actual_symbol_name"] +> safe fn name_in_rust(); +> } +> ``` + r[items.extern.attributes.link_name.syntax] It uses the [MetaNameValueStr] syntax to specify the name of the symbol. -```rust -unsafe extern { - #[link_name = "actual_symbol_name"] - safe fn name_in_rust(); -} -``` - r[items.extern.attributes.link_name.exclusive] Using this attribute with the `link_ordinal` attribute will result in a compiler error. From 1fb40c05e3e9de387ede6ade3482d2a3f6405782 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 16:35:29 -0700 Subject: [PATCH 4/7] Update link_name to use the attribute template --- src/items/external-blocks.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index f4d517a65..d5f509c4f 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -406,10 +406,22 @@ The *`link_name` [attribute][attributes]* may be specified on declarations insid > ``` r[items.extern.attributes.link_name.syntax] -It uses the [MetaNameValueStr] syntax to specify the name of the symbol. +The `link_name` attribute uses the [MetaNameValueStr] syntax to specify the name of the symbol. -r[items.extern.attributes.link_name.exclusive] -Using this attribute with the `link_ordinal` attribute will result in a compiler error. +r[items.extern.attributes.link_name.allowed-positions] +The `link_name` attribute may be specified on a function or static in an `extern` block. + +> [!NOTE] +> `rustc` currently warns in other positions, but this may be rejected in the future. + +r[items.extern.attributes.link_name.duplicates] +Only the last instance of `link_name` on an item is used to determine the symbol name. + +> [!NOTE] +> `rustc` currently warns on preceding duplicate `link_name` attributes. This may become an error in the future. + +r[items.extern.attributes.link_name.link_ordinal] +The `link_name` attribute may not be used with the [`link_ordinal`] attribute. r[items.extern.attributes.link_ordinal] ### The `link_ordinal` attribute @@ -460,3 +472,4 @@ restrictions as [regular function parameters]. [statics]: static-items.md [unwind-behavior]: functions.md#unwinding [value namespace]: ../names/namespaces.md +[`link_ordinal`]: items.extern.attributes.link_ordinal From 623041e6e82761fd3f1949ae033d25186fc47dec Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 3 Aug 2025 07:53:21 +0000 Subject: [PATCH 5/7] Revise `link_name` text --- src/items/external-blocks.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index d5f509c4f..590a5ef28 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -395,30 +395,30 @@ r[items.extern.attributes.link_name] ### The `link_name` attribute r[items.extern.attributes.link_name.intro] -The *`link_name` [attribute][attributes]* may be specified on declarations inside an `extern` block to indicate the symbol to import for the given function or static. +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. > [!EXAMPLE] > ```rust -> unsafe extern { +> unsafe extern "C" { > #[link_name = "actual_symbol_name"] > safe fn name_in_rust(); > } > ``` r[items.extern.attributes.link_name.syntax] -The `link_name` attribute uses the [MetaNameValueStr] syntax to specify the name of the symbol. +The `link_name` attribute uses the [MetaNameValueStr] syntax. r[items.extern.attributes.link_name.allowed-positions] -The `link_name` attribute may be specified on a function or static in an `extern` block. +The `link_name` attribute may only be applied to a function or static item in an `extern` block. > [!NOTE] -> `rustc` currently warns in other positions, but this may be rejected in the future. +> `rustc` currently accepts and ignores the attribute in other positions but lints against it. This may become a hard error in the future. r[items.extern.attributes.link_name.duplicates] Only the last instance of `link_name` on an item is used to determine the symbol name. > [!NOTE] -> `rustc` currently warns on preceding duplicate `link_name` attributes. This may become an error in the future. +> `rustc` lints against duplicate use of this attribute on uses preceding the last. This may become a hard error in the future. r[items.extern.attributes.link_name.link_ordinal] The `link_name` attribute may not be used with the [`link_ordinal`] attribute. From 67e70f50bb4e7afe1cf5d8b6567f878355115c0a Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 3 Aug 2025 07:54:48 +0000 Subject: [PATCH 6/7] Remove stray space --- src/items/extern-crates.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/extern-crates.md b/src/items/extern-crates.md index d0be3406f..93a5f01d7 100644 --- a/src/items/extern-crates.md +++ b/src/items/extern-crates.md @@ -104,7 +104,7 @@ r[items.extern-crate.no_link.duplicates] Duplicate instances of the `no_link` attribute are ignored. > [!NOTE] -> `rustc` lints against duplicate use of this attribute. +> `rustc` lints against duplicate use of this attribute. [identifier]: ../identifiers.md [RFC 940]: https://github.com/rust-lang/rfcs/blob/master/text/0940-hyphens-considered-harmful.md From b42bcdbd30283d4b03729225b155909701374479 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 3 Aug 2025 08:01:42 +0000 Subject: [PATCH 7/7] Add back language about where lint is fired Prior to a revision, the text on the `automatically_derived` attribute had described where the lint is fired. Let's add that back, with somewhat more elaborate language, as we're keeping this in other cases. --- src/attributes/derive.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/attributes/derive.md b/src/attributes/derive.md index aece0484b..9f2a3532e 100644 --- a/src/attributes/derive.md +++ b/src/attributes/derive.md @@ -96,7 +96,7 @@ r[attributes.derive.automatically_derived.duplicates] Duplicate instances of the `automatically_derived` attribute on the same implementation have no effect. > [!NOTE] -> `rustc` lints against duplicate use of this attribute. +> `rustc` lints against duplicate use of this attribute on uses following the first. r[attributes.derive.automatically_derived.behavior] The `automatically_derived` attribute has no behavior.