diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 6e8e624d17..7793daf070 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -285,9 +285,6 @@ The *`optimize` [attribute]* suggests an optimization goal for the attributed fu > pub fn example3() {} > ``` -> [!NOTE] -> For `rustc`, `-C opt-level=0` (the default) disables LLVM optimizations for the entire crate, and `optimize(size)` and `optimize(speed)` do not enable them for the attributed function. `rustc` still applies its own optimizations, other than inlining, to such a function. - r[attributes.codegen.optimize.syntax] The syntax for the `optimize` attribute is: @@ -368,6 +365,11 @@ The `optimize` attribute supports these modes: > > Settings that base their defaults on the optimization level, such as debug assertions and overflow checks, ignore this attribute and use the crate's optimization level. +> [!NOTE] +> For `rustc`, `#[optimize(size)]` and `#[optimize(speed)]` don't have much effect with `-C opt-level=0` (the default). This is because `-C opt-level=0` disables most of the LLVM optimization pipeline and these attributes do not enable it for attributed functions. +> +> Applying `#[optimize(size)]` to a function suggests you would prefer a smaller size over more speed for that function; applying `#[optimize(speed)]` suggests you would prefer more speed over a smaller size. Under optimization, `rustc` tries to give effect to these preferences. + r[attributes.codegen.optimize.inline] `#[optimize(none)]` may not be used with `#[inline]` or `#[inline(always)]` on the same function. It may be used with `#[inline(never)]`. (See [attributes.codegen.inline.optimize].)