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
{{ message }}
Repository navigation
Commit 6b8de48
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/attributes/codegen.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,6 +220,49 @@ Only the first use of the `no_builtins` attribute has effect.
220
220
> [!NOTE]
221
221
> `rustc` lints against any use following the first.
222
222
223
+
<!-- template:attributes -->
224
+
r[attributes.codegen.optimize]
225
+
## The `optimize` attribute
226
+
227
+
r[attributes.codegen.optimize.intro]
228
+
The*`optimize` [attribute]* suggests whether a function, inherent method, trait method, or closure should be optimized for size or speed.
229
+
230
+
> [!EXAMPLE]
231
+
> ```rust
232
+
> #[optimize(size)]
233
+
> pub fn example1() {}
234
+
>
235
+
> #[optimize(speed)]
236
+
> pub fn example2() {}
237
+
> ```
238
+
239
+
r[attributes.codegen.optimize.syntax]
240
+
The syntax for the `optimize` attribute is:
241
+
242
+
```grammar,attributes
243
+
@root OptimizeAttribute->
244
+
`optimize` `(` `size` `)`
245
+
| `optimize` `(` `speed` `)`
246
+
```
247
+
248
+
r[attributes.codegen.optimize.allowed-positions]
249
+
The `optimize` attribute may only be applied to [closures], [async blocks], [free functions], [associated functions] in an [inherent impl] or [traitimpl], and associated functions in a [trait definition].
250
+
251
+
r[attributes.codegen.optimize.duplicates]
252
+
Only the first use of `optimize` on a function has effect.
253
+
254
+
> [!NOTE]
255
+
> `rustc` lints against any use following the first.
256
+
257
+
r[attributes.codegen.optimize.modes]
258
+
The `optimize` attribute supports these modes:
259
+
260
+
- `#[optimize(size)]` suggests prioritizing minimizing code size, potentially at the cost of execution performance.
261
+
- `#[optimize(speed)]` suggests prioritizing execution performance, potentially at the cost of code size.
262
+
263
+
> [!NOTE]
264
+
> In every form the attribute is a hint.The compiler may ignore it.
0 commit comments