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 e9f9d99
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/attributes/codegen.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -235,6 +235,51 @@ Only the first use of the `no_builtins` attribute has effect.
235
235
> [!NOTE]
236
236
> `rustc` lints against any use following the first.
237
237
238
+
<!-- template:attributes -->
239
+
r[attributes.codegen.optimize]
240
+
## The `optimize` attribute
241
+
242
+
r[attributes.codegen.optimize.intro]
243
+
The*`optimize` [attribute]* suggests whether a function, inherent method, trait method, or closure should be optimized for size or speed.
244
+
245
+
> [!EXAMPLE]
246
+
> ```rust
247
+
> #[optimize(size)]
248
+
> pub fn example1() {}
249
+
>
250
+
> #[optimize(speed)]
251
+
> pub fn example2() {}
252
+
>
253
+
> #[optimize(none)]
254
+
> pub fn example3() {}
255
+
> ```
256
+
257
+
r[attributes.codegen.optimize.syntax]
258
+
The syntax for the `optimize` attribute is:
259
+
260
+
```grammar,attributes
261
+
@root OptimizeAttribute->
262
+
`optimize` `(` `size` `)`
263
+
| `optimize` `(` `speed` `)`
264
+
| `optimize` `(` `none` `)`
265
+
```
266
+
267
+
r[attributes.codegen.optimize.allowed-positions]
268
+
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].
269
+
270
+
r[attributes.codegen.optimize.duplicates]
271
+
Applying multiple `optimize` attributes to the same function is an error.
272
+
273
+
r[attributes.codegen.optimize.modes]
274
+
The `optimize` attribute supports these modes:
275
+
276
+
- `#[optimize(size)]` suggests prioritizing minimizing code size, potentially at the cost of execution performance.
277
+
- `#[optimize(speed)]` suggests prioritizing execution performance, potentially at the cost of code size.
278
+
- `#[optimize(none)]` suggests not optimizing the function, with similar effects to applying -Copt-level=0 locally.
279
+
280
+
> [!NOTE]
281
+
> In every form the attribute is a hint.The compiler may ignore it.
0 commit comments