@@ -69,19 +69,30 @@ features. It uses the [_MetaListNameValueStr_] syntax with a single key of
69
69
``` rust
70
70
# #[cfg(target_feature = " avx2" )]
71
71
#[target_feature(enable = " avx2" )]
72
- unsafe fn foo_avx2 () {}
72
+ fn foo_avx2 () {}
73
73
```
74
74
75
75
r[ attributes.codegen.target_feature.arch]
76
76
Each [ target architecture] has a set of features that may be enabled. It is an
77
77
error to specify a feature for a target architecture that the crate is not
78
78
being compiled for.
79
79
80
+ r[ attributes.codegen.target_feature.closures]
81
+ Closures defined within a ` target_feature ` -annotated function inherit the
82
+ attribute from the enclosing function.
83
+
80
84
r[ attributes.codegen.target_feature.target-ub]
81
85
It is [ undefined behavior] to call a function that is compiled with a feature
82
86
that is not supported on the current platform the code is running on, * except*
83
87
if the platform explicitly documents this to be safe.
84
88
89
+ r[ attributes.codegen.target_feature.safety]
90
+ Because of this, on many platforms safe functions and closures marked with
91
+ ` target_feature ` do not implement Fn traits, cannot be coerced to safe ` fn `
92
+ pointers and require ` unsafe ` to be called. These restrictions are lifted in
93
+ contexts where the set of features enabled in the callee is a subset of the set
94
+ of features enabled in the caller.
95
+
85
96
r[ attributes.codegen.target_feature.inline]
86
97
Functions marked with ` target_feature ` are not inlined into a context that
87
98
does not support the given features. The ` #[inline(always)] ` attribute may not
@@ -98,8 +109,7 @@ r[attributes.codegen.target_feature.x86]
98
109
99
110
100
111
Executing code with unsupported features is undefined behavior on this platform.
101
- Hence this platform requires that ` #[target_feature] ` is only applied to [ ` unsafe `
102
- functions] [ unsafe function ] .
112
+ Hence on this platform usage of ` #[target_feature] ` functions is usually unsafe.
103
113
104
114
Feature | Implicitly Enables | Description
105
115
------------|--------------------|-------------------
@@ -166,8 +176,7 @@ r[attributes.codegen.target_feature.aarch64]
166
176
#### ` aarch64 `
167
177
168
178
169
- This platform requires that ` #[target_feature] ` is only applied to [ ` unsafe `
170
- functions] [ unsafe function ] .
179
+ On this platform usage of ` #[target_feature] ` functions is usually unsafe.
171
180
172
181
Further documentation on these features can be found in the [ ARM Architecture
173
182
Reference Manual] , or elsewhere on [ developer.arm.com] .
@@ -231,8 +240,7 @@ r[attributes.codegen.target_feature.riscv]
231
240
#### ` riscv32 ` or ` riscv64 `
232
241
233
242
234
- This platform requires that ` #[target_feature] ` is only applied to [ ` unsafe `
235
- functions] [ unsafe function ] .
243
+ On this platform usage of ` #[target_feature] ` functions is usually unsafe.
236
244
237
245
Further documentation on these features can be found in their respective
238
246
specification. Many specifications are described in the [ RISC-V ISA Manual] or
@@ -293,12 +301,11 @@ r[attributes.codegen.target_feature.wasm]
293
301
#### ` wasm32 ` or ` wasm64 `
294
302
295
303
296
- ` #[target_feature] ` may be used with both safe and
297
- [ ` unsafe ` functions] [ unsafe function ] on Wasm platforms. It is impossible to
298
- cause undefined behavior via the ` #[target_feature] ` attribute because
299
- attempting to use instructions unsupported by the Wasm engine will fail at load
300
- time without the risk of being interpreted in a way different from what the
301
- compiler expected.
304
+ Safe ` #[target_feature] ` functions may always be used in safe contexts on Wasm
305
+ platforms. It is impossible to cause undefined behavior via the
306
+ ` #[target_feature] ` attribute because attempting to use instructions
307
+ unsupported by the Wasm engine will fail at load time without the risk of being
308
+ interpreted in a way different from what the compiler expected.
302
309
303
310
Feature | Implicitly Enables | Description
304
311
----------------------|---------------------|-------------------
0 commit comments