Skip to content

Commit 1d719db

Browse files
committed
Update target_feature to use the attribute template
1 parent 3b3a7b8 commit 1d719db

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
@@ -93,7 +93,7 @@ r[attributes.codegen.target_feature]
9393
## The `target_feature` attribute
9494

9595
r[attributes.codegen.target_feature.intro]
96-
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.
96+
The *`target_feature` [attribute]* may be applied to a function to enable code generation of that function for specific platform architecture features.
9797

9898
> [!EXAMPLE]
9999
> ```rust
@@ -102,6 +102,37 @@ The *`target_feature` [attribute]* may be applied to a function to enable code g
102102
> fn foo_avx2() {}
103103
> ```
104104
105+
r[attributes.codegen.target_feature.syntax]
106+
The syntax for the `target_feature` attribute is:
107+
108+
```grammar,attributes
109+
@root TargetFeatureAttribute ->
110+
`target_feature` `(` `enable` `=` (STRING_LITERAL | RAW_STRING_LITERAL) `)`
111+
```
112+
113+
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.
114+
115+
r[attributes.codegen.target_feature.allowed-positions]
116+
The `target_feature` may only be applied to:
117+
118+
- [Free functions][items.fn]
119+
- [Inherent associated functions][items.associated.fn]
120+
- [Trait impl functions][items.impl.trait]
121+
- [Trait definition functions][items.traits] with a body
122+
123+
It is not allowed on the following places:
124+
125+
- [the `main` function][crate.main]
126+
- a [`panic_handler` function][panic.panic_handler]
127+
- safe trait methods
128+
- safe default functions in traits
129+
130+
> [!NOTE]
131+
> `rustc` currently warns on some positions where it is ignored, but this may become an error in the future.
132+
133+
r[attributes.codegen.target_feature.duplicates]
134+
If the `target_feature` attribute is specified multiple times on an item, then the union of all the specified features are enabled.
135+
105136
r[attributes.codegen.target_feature.arch]
106137
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.
107138

@@ -151,14 +182,6 @@ fn bar_sse2() {
151182
r[attributes.codegen.target_feature.fn-traits]
152183
A function with a `#[target_feature]` attribute *never* implements the `Fn` family of traits, although closures inheriting features from the enclosing function do.
153184

154-
r[attributes.codegen.target_feature.allowed-positions]
155-
The `#[target_feature]` attribute is not allowed on the following places:
156-
157-
- [the `main` function][crate.main]
158-
- a [`panic_handler` function][panic.panic_handler]
159-
- safe trait methods
160-
- safe default functions in traits
161-
162185
r[attributes.codegen.target_feature.inline]
163186
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.
164187

0 commit comments

Comments
 (0)