Skip to content

Commit d2d1d66

Browse files
committed
Add no_mangle template rules
1 parent 6e5bc04 commit d2d1d66

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/abi.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,34 @@ The *`no_mangle` attribute* may be used on functions and statics to disable stan
7272
extern "C" fn foo() {}
7373
```
7474

75+
r[abi.no_mangle.syntax]
76+
The `no_mangle` attribute uses the [MetaWord] syntax and thus does not take any inputs.
77+
78+
r[abi.no_mangle.allowed-positions]
79+
The `no_mangle` attribute may only be applied to:
80+
81+
- [Static items][items.static]
82+
- [Free functions][items.fn]
83+
- [Inherent associated functions][items.associated.fn]
84+
- [Trait impl functions][items.impl.trait]
85+
86+
It may not be used with a [closure].
87+
88+
> [!NOTE]
89+
> `rustc` currently warns in other positions, but this may be rejected in the future.
90+
91+
<!-- TODO: Currently it works on a trait function with a body, but generates a warning about being phased out. how do we document that?
92+
https://github.com/rust-lang/rust/pull/86492#issuecomment-885682960
93+
-->
94+
95+
<!-- TODO: should this clarify that external block items are already unmangled?, and thus the attribute does nothing? Currently it is "phased out" warning. -->
96+
97+
r[abi.no_mangle.duplicates]
98+
Only the first instance of `no_mangle` on an item is honored. Subsequent `no_mangle` attributes are ignored.
99+
100+
> [!NOTE]
101+
> `rustc` currently warns on subsequent duplicate `no_mangle` attributes.
102+
75103
r[abi.no_mangle.unsafe]
76104
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.
77105

@@ -133,6 +161,7 @@ r[abi.export_name.edition2024]
133161
134162
[`static` items]: items/static-items.md
135163
[attribute]: attributes.md
164+
[closure]: expr.closure
136165
[extern functions]: items/functions.md#extern-function-qualifier
137166
[external blocks]: items/external-blocks.md
138167
[function]: items/functions.md

0 commit comments

Comments
 (0)