@@ -69,19 +69,30 @@ features. It uses the [_MetaListNameValueStr_] syntax with a single key of
6969``` rust
7070# #[cfg(target_feature = " avx2" )]
7171#[target_feature(enable = " avx2" )]
72- unsafe fn foo_avx2 () {}
72+ fn foo_avx2 () {}
7373```
7474
7575r[ attributes.codegen.target_feature.arch]
7676Each [ target architecture] has a set of features that may be enabled. It is an
7777error to specify a feature for a target architecture that the crate is not
7878being compiled for.
7979
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+
8084r[ attributes.codegen.target_feature.target-ub]
8185It is [ undefined behavior] to call a function that is compiled with a feature
8286that is not supported on the current platform the code is running on, * except*
8387if the platform explicitly documents this to be safe.
8488
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+
8596r[ attributes.codegen.target_feature.inline]
8697Functions marked with ` target_feature ` are not inlined into a context that
8798does not support the given features. The ` #[inline(always)] ` attribute may not
@@ -98,8 +109,7 @@ r[attributes.codegen.target_feature.x86]
98109
99110
100111Executing 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.
103113
104114Feature | Implicitly Enables | Description
105115------------|--------------------|-------------------
@@ -166,8 +176,7 @@ r[attributes.codegen.target_feature.aarch64]
166176#### ` aarch64 `
167177
168178
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.
171180
172181Further documentation on these features can be found in the [ ARM Architecture
173182Reference Manual] , or elsewhere on [ developer.arm.com] .
@@ -231,8 +240,7 @@ r[attributes.codegen.target_feature.riscv]
231240#### ` riscv32 ` or ` riscv64 `
232241
233242
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.
236244
237245Further documentation on these features can be found in their respective
238246specification. Many specifications are described in the [ RISC-V ISA Manual] or
@@ -293,12 +301,11 @@ r[attributes.codegen.target_feature.wasm]
293301#### ` wasm32 ` or ` wasm64 `
294302
295303
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.
302309
303310Feature | Implicitly Enables | Description
304311----------------------|---------------------|-------------------
0 commit comments