Skip to content

Commit 6fbebbb

Browse files
committed
Update target_feature to use the attribute template
1 parent de89f6f commit 6fbebbb

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

src/attributes/codegen.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ r[attributes.codegen.target_feature]
185185
## The `target_feature` attribute
186186
187187
r[attributes.codegen.target_feature.intro]
188-
The *`target_feature` [attribute]* may be applied to a function to enable code generation of that function for specific platform architecture features. It uses the [MetaListNameValueStr] syntax with a single key of `enable` whose value is a string of comma-separated feature names to enable.
188+
The *`target_feature` [attribute]* may be applied to a function to enable code generation of that function for specific platform architecture features.
189189
190190
> [!EXAMPLE]
191191
> ```rust
@@ -194,6 +194,37 @@ The *`target_feature` [attribute]* may be applied to a function to enable code g
194194
> fn foo_avx2() {}
195195
> ```
196196
197+
r[attributes.codegen.target_feature.syntax]
198+
The syntax for the `target_feature` attribute is:
199+
200+
```grammar,attributes
201+
@root TargetFeatureAttribute ->
202+
`target_feature` `(` `enable` `=` (STRING_LITERAL | RAW_STRING_LITERAL) `)`
203+
```
204+
205+
The given string is a comma-separated list of feature names to enable. See [available features](#available-features) for the list of features that are available.
206+
207+
r[attributes.codegen.target_feature.allowed-positions]
208+
The `target_feature` may only be applied to:
209+
210+
- [Free functions][items.fn]
211+
- [Inherent associated functions][items.associated.fn]
212+
- [Trait impl functions][items.impl.trait]
213+
- [Trait definition functions][items.traits] with a body
214+
215+
It is not allowed on the following places:
216+
217+
- [the `main` function][crate.main]
218+
- a [`panic_handler` function][panic.panic_handler]
219+
- safe trait methods
220+
- safe default functions in traits
221+
222+
> [!NOTE]
223+
> `rustc` currently warns on some positions where it is ignored, but this may become an error in the future.
224+
225+
r[attributes.codegen.target_feature.duplicates]
226+
If the `target_feature` attribute is specified multiple times on an item, then the union of all the specified features are enabled.
227+
197228
r[attributes.codegen.target_feature.arch]
198229
Each [target architecture] has a set of features that may be enabled. It is an error to specify a feature for a target architecture that the crate is not being compiled for.
199230
@@ -243,14 +274,6 @@ fn bar_sse2() {
243274
r[attributes.codegen.target_feature.fn-traits]
244275
A function with a `#[target_feature]` attribute *never* implements the `Fn` family of traits, although closures inheriting features from the enclosing function do.
245276

246-
r[attributes.codegen.target_feature.allowed-positions]
247-
The `#[target_feature]` attribute is not allowed on the following places:
248-
249-
- [the `main` function][crate.main]
250-
- a [`panic_handler` function][panic.panic_handler]
251-
- safe trait methods
252-
- safe default functions in traits
253-
254277
r[attributes.codegen.target_feature.inline]
255278
Functions marked with `target_feature` are not inlined into a context that does not support the given features. The `#[inline(always)]` attribute may not be used with a `target_feature` attribute.
256279

0 commit comments

Comments
 (0)