You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/attributes/codegen.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,17 @@ The `cold` attribute may only be applied to functions with [bodies] --- [closure
110
110
111
111
<!--TODO: rustc currently seems to allow cold on a trait function without a body, but it appears to be ignored.I think that may be a bug, and it should at least warn if not reject (like inline does).-->
112
112
113
+
r[attributes.codegen.cold.extern-custom]
114
+
The `cold` attribute may not be applied to an [`extern "custom"` function].
115
+
116
+
```rust,compile_fail
117
+
#[cold] // ERROR: Not allowed.
118
+
#[unsafe(naked)]
119
+
unsafeextern "custom" fn f() {
120
+
core::arch::naked_asm!("ret")
121
+
}
122
+
```
123
+
113
124
r[attributes.codegen.cold.duplicates]
114
125
Only the first use of `cold` on a function has effect.
115
126
@@ -144,6 +155,9 @@ The *`naked` [attribute]* prevents the compiler from emitting a function prologu
144
155
> # }
145
156
> ```
146
157
158
+
> [!NOTE]
159
+
> The assembly code of a naked function often does not follow the calling convention of any ABI known to the compiler.Such a function should be declared as an [`extern "custom"` function][items.fn.extern.custom].
160
+
147
161
r[attributes.codegen.naked.syntax]
148
162
The `naked` attribute uses the [MetaWord] syntax.
149
163
@@ -900,6 +914,7 @@ If the address of the function is taken as a function pointer, the low bit of th
Patterns are not allowed in parameters, only [IDENTIFIER] or `_` may be used.
49
49
50
50
r[items.extern.fn.qualifiers]
51
-
The `safe` and `unsafe` function qualifiers are allowed, but other function qualifiers (e.g. `const`, `async`, `extern`) are not.
51
+
The `safe` and `unsafe` function qualifiers are allowed, but other function qualifiers (e.g. `const`, `async`, `extern`) are not. The `safe` qualifier is rejected in `extern "custom"` blocks.
52
52
53
53
r[items.extern.fn.foreign-abi]
54
54
Functions within external blocks may be called by Rust code, just like functions defined in Rust. The Rust compiler automatically translates between the Rust ABI and the foreign ABI.
@@ -112,6 +112,9 @@ r[items.extern.abi.system]
112
112
r[items.extern.abi.unwind]
113
113
* `extern "C-unwind"` and `extern "system-unwind"` ---Identical to `"C"` and `"system"`, respectively, but with [different behavior][unwind-behavior] when the callee unwinds (by panicking or throwing a C++ style exception).
114
114
115
+
r[items.extern.abi.custom]
116
+
* `unsafeextern "custom"` ---A custom ABI that is not known to the compiler.
117
+
115
118
r[items.extern.abi.platform]
116
119
There are also some platform-specific ABI strings:
0 commit comments