From 002aed6e23964d994684b049122d8e9281ae1d81 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 14:21:50 -0700 Subject: [PATCH 1/9] Move abi.no_mangle.publicly-exported and tweak wording This moves it below to match the template of having behavioral rules after the syntax. --- src/abi.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/abi.md b/src/abi.md index cf6f32c90e..37392912be 100644 --- a/src/abi.md +++ b/src/abi.md @@ -67,9 +67,6 @@ r[abi.no_mangle] r[abi.no_mangle.intro] The *`no_mangle` attribute* may be used on any [item] to disable standard symbol name mangling. The symbol for the item will be the identifier of the item's name. -r[abi.no_mangle.publicly-exported] -Additionally, the item will be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute). - r[abi.no_mangle.unsafe] This attribute is unsafe as an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. @@ -82,6 +79,9 @@ r[abi.no_mangle.edition2024] > [!EDITION-2024] > Before the 2024 edition it is allowed to use the `no_mangle` attribute without the `unsafe` qualification. +r[abi.no_mangle.publicly-exported] +In addition to disabling name mangling, the item will be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute). + r[abi.link_section] ## The `link_section` attribute From cebafe19aecffc9975bc7d4e57aa6c82f5fa7045 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 14:23:11 -0700 Subject: [PATCH 2/9] Move abi.no_mangle.unsafe and tweak wording This is to match the template order. --- src/abi.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/abi.md b/src/abi.md index 37392912be..5f15cd91e6 100644 --- a/src/abi.md +++ b/src/abi.md @@ -67,14 +67,14 @@ r[abi.no_mangle] r[abi.no_mangle.intro] The *`no_mangle` attribute* may be used on any [item] to disable standard symbol name mangling. The symbol for the item will be the identifier of the item's name. -r[abi.no_mangle.unsafe] -This attribute is unsafe as an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. - ```rust #[unsafe(no_mangle)] extern "C" fn foo() {} ``` +r[abi.no_mangle.unsafe] +The `no_mangle` attribute must be marked with [`unsafe`][attributes.safety] because an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. + r[abi.no_mangle.edition2024] > [!EDITION-2024] > Before the 2024 edition it is allowed to use the `no_mangle` attribute without the `unsafe` qualification. From 5b208913e489d88f0dfa929e13d370490caf3498 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 14:23:59 -0700 Subject: [PATCH 3/9] Update the no_mangle introduction It doesn't really work with any item, it is functions and statics. --- src/abi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi.md b/src/abi.md index 5f15cd91e6..40aa80f1e1 100644 --- a/src/abi.md +++ b/src/abi.md @@ -65,7 +65,7 @@ r[abi.no_mangle] ## The `no_mangle` attribute r[abi.no_mangle.intro] -The *`no_mangle` attribute* may be used on any [item] to disable standard symbol name mangling. The symbol for the item will be the identifier of the item's name. +The *`no_mangle` attribute* may be used on functions and statics to disable standard symbol name mangling. The symbol for the item will be the identifier of the item's name. ```rust #[unsafe(no_mangle)] From 5e4e93dfc95ddd80788a689eb8fd27fcb8fc823d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 14:24:46 -0700 Subject: [PATCH 4/9] Add no_mangle template rules --- src/abi.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/abi.md b/src/abi.md index 40aa80f1e1..8bc17b871f 100644 --- a/src/abi.md +++ b/src/abi.md @@ -72,6 +72,34 @@ The *`no_mangle` attribute* may be used on functions and statics to disable stan extern "C" fn foo() {} ``` +r[abi.no_mangle.syntax] +The `no_mangle` attribute uses the [MetaWord] syntax and thus does not take any inputs. + +r[abi.no_mangle.allowed-positions] +The `no_mangle` attribute may only be applied to: + +- [Static items][items.static] +- [Free functions][items.fn] +- [Inherent associated functions][items.associated.fn] +- [Trait impl functions][items.impl.trait] + +It may not be used with a [closure]. + +> [!NOTE] +> `rustc` currently warns in other positions, but this may be rejected in the future. + + + + + +r[abi.no_mangle.duplicates] +Only the first instance of `no_mangle` on an item is honored. Subsequent `no_mangle` attributes are ignored. + +> [!NOTE] +> `rustc` currently warns on subsequent duplicate `no_mangle` attributes. + r[abi.no_mangle.unsafe] The `no_mangle` attribute must be marked with [`unsafe`][attributes.safety] because an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. @@ -141,6 +169,7 @@ r[abi.export_name.edition2024] > Before the 2024 edition it is allowed to use the `export_name` attribute without the `unsafe` qualification. [attribute]: attributes.md +[closure]: expr.closure [extern functions]: items/functions.md#extern-function-qualifier [external blocks]: items/external-blocks.md [function]: items/functions.md From 8aefd08c5a0af769bb08f96003e589cac2697e23 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 14:25:13 -0700 Subject: [PATCH 5/9] Add abi.no_mangle.export_name This specifies the conflict between no_mangle and export_name. --- src/abi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi.md b/src/abi.md index 8bc17b871f..bcf0f87e8c 100644 --- a/src/abi.md +++ b/src/abi.md @@ -100,6 +100,9 @@ Only the first instance of `no_mangle` on an item is honored. Subsequent `no_man > [!NOTE] > `rustc` currently warns on subsequent duplicate `no_mangle` attributes. +r[abi.no_mangle.export_name] +If `no_mangle` is used with [`export_name`][abi.export_name], then the `export_name` is used instead. + r[abi.no_mangle.unsafe] The `no_mangle` attribute must be marked with [`unsafe`][attributes.safety] because an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. From fca4168a0bd5b266f49795151b36cfdf771740c2 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 14:25:32 -0700 Subject: [PATCH 6/9] Add abi.no_mangle.ascii-only This is a restriction that wasn't previously documented. --- src/abi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi.md b/src/abi.md index bcf0f87e8c..858a2e0174 100644 --- a/src/abi.md +++ b/src/abi.md @@ -113,6 +113,9 @@ r[abi.no_mangle.edition2024] r[abi.no_mangle.publicly-exported] In addition to disabling name mangling, the item will be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute). +r[abi.no_mangle.ascii-only] +`no_mangle` may only be used on items with a name that only contains ASCII characters. + r[abi.link_section] ## The `link_section` attribute From e10309426478e4cc4e04efe95c1ef37cce37359f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:45:41 -0700 Subject: [PATCH 7/9] Move no_mangle example into block --- src/abi.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/abi.md b/src/abi.md index 858a2e0174..ac6e74fe8f 100644 --- a/src/abi.md +++ b/src/abi.md @@ -67,10 +67,11 @@ r[abi.no_mangle] r[abi.no_mangle.intro] The *`no_mangle` attribute* may be used on functions and statics to disable standard symbol name mangling. The symbol for the item will be the identifier of the item's name. -```rust -#[unsafe(no_mangle)] -extern "C" fn foo() {} -``` +> [!EXAMPLE] +> ```rust +> #[unsafe(no_mangle)] +> extern "C" fn foo() {} +> ``` r[abi.no_mangle.syntax] The `no_mangle` attribute uses the [MetaWord] syntax and thus does not take any inputs. From 0bda9ef95f33997736c94e9414bb0639b5d3f4e7 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 30 Jun 2025 14:47:58 -0700 Subject: [PATCH 8/9] Add abi.no_mangle.generic --- src/abi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi.md b/src/abi.md index ac6e74fe8f..f014a4ffbf 100644 --- a/src/abi.md +++ b/src/abi.md @@ -117,6 +117,9 @@ In addition to disabling name mangling, the item will be publicly exported from r[abi.no_mangle.ascii-only] `no_mangle` may only be used on items with a name that only contains ASCII characters. +r[abi.no_mangle.generic] +`no_mangle` has no effect on generic items. + r[abi.link_section] ## The `link_section` attribute From bcd64d89087c7619c8f51d84e6d5868dc65337ab Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 22 Sep 2025 13:16:54 -0700 Subject: [PATCH 9/9] Minor update of `no_mangle` More closely align with the template, and some minor word tweaks. --- src/abi.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/abi.md b/src/abi.md index f014a4ffbf..d5fd07bed0 100644 --- a/src/abi.md +++ b/src/abi.md @@ -61,6 +61,7 @@ Only the first use of `used` on an item has effect. > [!NOTE] > `rustc` lints against any use following the first. + r[abi.no_mangle] ## The `no_mangle` attribute @@ -74,7 +75,7 @@ The *`no_mangle` attribute* may be used on functions and statics to disable stan > ``` r[abi.no_mangle.syntax] -The `no_mangle` attribute uses the [MetaWord] syntax and thus does not take any inputs. +The `no_mangle` attribute uses the [MetaWord] syntax. r[abi.no_mangle.allowed-positions] The `no_mangle` attribute may only be applied to: @@ -87,7 +88,7 @@ The `no_mangle` attribute may only be applied to: It may not be used with a [closure]. > [!NOTE] -> `rustc` currently warns in other positions, but this may be rejected in the future. +> `rustc` ignores use in other positions but lints against it. This may become an error in the future. r[abi.no_mangle.duplicates] -Only the first instance of `no_mangle` on an item is honored. Subsequent `no_mangle` attributes are ignored. +The `no_mangle` attribute may be used any number of times on a form. > [!NOTE] -> `rustc` currently warns on subsequent duplicate `no_mangle` attributes. +> `rustc` lints against any use following the first. r[abi.no_mangle.export_name] If `no_mangle` is used with [`export_name`][abi.export_name], then the `export_name` is used instead.