From 986b500952c0daac34bf578986c7059cd799714b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 17:56:03 -0700 Subject: [PATCH 1/9] Unwrap cold and inline --- src/attributes/codegen.md | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index b38b578312..335b9500a0 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -7,23 +7,16 @@ r[attributes.codegen.hint] ## Optimization hints r[attributes.codegen.hint.cold-inline] -The `cold` and `inline` [attributes] give suggestions to generate code in a -way that may be faster than what it would do without the hint. The attributes -are only hints, and may be ignored. +The `cold` and `inline` [attributes] give suggestions to generate code in a way that may be faster than what it would do without the hint. The attributes are only hints, and may be ignored. r[attributes.codegen.hint.usage] -Both attributes can be used on [functions]. When applied to a function in a -[trait], they apply only to that function when used as a default function for -a trait implementation and not to all trait implementations. The attributes -have no effect on a trait function without a body. +Both attributes can be used on [functions]. When applied to a function in a [trait], they apply only to that function when used as a default function for a trait implementation and not to all trait implementations. The attributes have no effect on a trait function without a body. r[attributes.codegen.inline] ### The `inline` attribute r[attributes.codegen.inline.intro] -The *`inline` [attribute]* suggests that a copy of the attributed function -should be placed in the caller, rather than generating code to call the -function where it is defined. +The *`inline` [attribute]* suggests that a copy of the attributed function should be placed in the caller, rather than generating code to call the function where it is defined. > [!NOTE] > The `rustc` compiler automatically inlines functions based on internal heuristics. Incorrectly inlining functions can make the program slower, so this attribute should be used with care. @@ -32,10 +25,8 @@ r[attributes.codegen.inline.modes] There are three ways to use the inline attribute: * `#[inline]` *suggests* performing an inline expansion. -* `#[inline(always)]` *suggests* that an inline expansion should always be - performed. -* `#[inline(never)]` *suggests* that an inline expansion should never be - performed. +* `#[inline(always)]` *suggests* that an inline expansion should always be performed. +* `#[inline(never)]` *suggests* that an inline expansion should never be performed. > [!NOTE] > `#[inline]` in every form is a hint, with no *requirements* on the language to place a copy of the attributed function in the caller. @@ -43,8 +34,7 @@ There are three ways to use the inline attribute: r[attributes.codegen.cold] ### The `cold` attribute -The *`cold` [attribute]* suggests that the attributed function is unlikely to -be called. +The *`cold` [attribute]* suggests that the attributed function is unlikely to be called. r[attributes.codegen.naked] ## The `naked` attribute From 0b0232719b39243f194ac5e5c2fcac363399ef98 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 18:42:50 -0700 Subject: [PATCH 2/9] Convert items.fn.attributes.builtin-attributes to a list --- src/items/functions.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/items/functions.md b/src/items/functions.md index e988077eb5..264a07f908 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -417,11 +417,20 @@ fn documented() { > Except for lints, it is idiomatic to only use outer attributes on function items. r[items.fn.attributes.builtin-attributes] -The attributes that have meaning on a function are [`cfg`], [`cfg_attr`], [`deprecated`], -[`doc`], [`export_name`], [`link_section`], [`no_mangle`], [the lint check -attributes], [`must_use`], [the procedural macro attributes], [the testing -attributes], and [the optimization hint attributes]. Functions also accept -attributes macros. +The attributes that have meaning on a function are: + +- [`cfg_attr`] +- [`cfg`] +- [`deprecated`] +- [`doc`] +- [`export_name`] +- [`link_section`] +- [`must_use`] +- [`no_mangle`] +- [Lint check attributes] +- [Optimization hint attributes] +- [Procedural macro attributes] +- [Testing attributes] r[items.fn.param-attributes] ## Attributes on function parameters @@ -471,10 +480,10 @@ fn foo_oof(#[some_inert_attribute] arg: u8) { [attributes]: ../attributes.md [`cfg`]: ../conditional-compilation.md#the-cfg-attribute [`cfg_attr`]: ../conditional-compilation.md#the-cfg_attr-attribute -[the lint check attributes]: ../attributes/diagnostics.md#lint-check-attributes -[the procedural macro attributes]: ../procedural-macros.md -[the testing attributes]: ../attributes/testing.md -[the optimization hint attributes]: ../attributes/codegen.md#optimization-hints +[lint check attributes]: ../attributes/diagnostics.md#lint-check-attributes +[procedural macro attributes]: ../procedural-macros.md#attribute-macros +[testing attributes]: ../attributes/testing.md +[optimization hint attributes]: ../attributes/codegen.md#optimization-hints [`deprecated`]: ../attributes/diagnostics.md#the-deprecated-attribute [`doc`]: ../../rustdoc/the-doc-attribute.html [`must_use`]: ../attributes/diagnostics.md#the-must_use-attribute From e7b9db639ac90523d3704f52f562c32cb0acd041 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 18:48:11 -0700 Subject: [PATCH 3/9] Remove "optimization hints" section I didn't feel like this section was pulling its weight. It also wasn't entirely correct. --- src/attributes/codegen.md | 9 --------- src/items/functions.md | 6 ++++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 335b9500a0..496645e333 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -3,15 +3,6 @@ r[attributes.codegen] The following [attributes] are used for controlling code generation. -r[attributes.codegen.hint] -## Optimization hints - -r[attributes.codegen.hint.cold-inline] -The `cold` and `inline` [attributes] give suggestions to generate code in a way that may be faster than what it would do without the hint. The attributes are only hints, and may be ignored. - -r[attributes.codegen.hint.usage] -Both attributes can be used on [functions]. When applied to a function in a [trait], they apply only to that function when used as a default function for a trait implementation and not to all trait implementations. The attributes have no effect on a trait function without a body. - r[attributes.codegen.inline] ### The `inline` attribute diff --git a/src/items/functions.md b/src/items/functions.md index 264a07f908..96bbc0b39b 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -421,14 +421,15 @@ The attributes that have meaning on a function are: - [`cfg_attr`] - [`cfg`] +- [`cold`] - [`deprecated`] - [`doc`] - [`export_name`] +- [`inline`] - [`link_section`] - [`must_use`] - [`no_mangle`] - [Lint check attributes] -- [Optimization hint attributes] - [Procedural macro attributes] - [Testing attributes] @@ -483,7 +484,8 @@ fn foo_oof(#[some_inert_attribute] arg: u8) { [lint check attributes]: ../attributes/diagnostics.md#lint-check-attributes [procedural macro attributes]: ../procedural-macros.md#attribute-macros [testing attributes]: ../attributes/testing.md -[optimization hint attributes]: ../attributes/codegen.md#optimization-hints +[`cold`]: ../attributes/codegen.md#the-cold-attribute +[`inline`]: ../attributes/codegen.md#the-inline-attribute [`deprecated`]: ../attributes/diagnostics.md#the-deprecated-attribute [`doc`]: ../../rustdoc/the-doc-attribute.html [`must_use`]: ../attributes/diagnostics.md#the-must_use-attribute From 9160b207ec0e734ceb690c0493d83d6451fe5a1b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 18:48:42 -0700 Subject: [PATCH 4/9] Update inline to use the attribute template --- src/attributes/codegen.md | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 496645e333..21a28539c7 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -9,9 +9,49 @@ r[attributes.codegen.inline] r[attributes.codegen.inline.intro] The *`inline` [attribute]* suggests that a copy of the attributed function should be placed in the caller, rather than generating code to call the function where it is defined. +> [!EXAMPLE] +> ```rust +> #[inline] +> pub fn example1() {} +> +> #[inline(always)] +> pub fn example2() {} +> +> #[inline(never)] +> pub fn example3() {} +> ``` + > [!NOTE] > The `rustc` compiler automatically inlines functions based on internal heuristics. Incorrectly inlining functions can make the program slower, so this attribute should be used with care. +r[attributes.codegen.inline.syntax] +The syntax for the `inline` attribute is: + +```grammar,attributes +@root InlineAttribute -> + `inline` `(` `always` `)` + | `inline` `(` `never` `)` + | `inline` +``` + +r[attributes.codegen.inline.allowed-positions] +The `inline` attribute may only be used on: + +- [Free functions][items.fn] +- [Inherent associated functions][items.associated.fn] +- [Trait impl functions][items.impl.trait] +- [Trait definition functions][items.traits] with a body +- [Closures][expr.closure] + +> [!NOTE] +> `rustc` currently warns when `inline` is used in some other positions. This may become an error in the future. + +r[attributes.codegen.inline.duplicates] +Only the first instance of `inline` on an item is honored. Subsequent `inline` attributes are ignored. + +> [!NOTE] +> `rustc` currently warns on duplicate `inline` attributes. This may become an error in the future. + r[attributes.codegen.inline.modes] There are three ways to use the inline attribute: From ebe4496ab313100ae2fbb6419e9119aeb778a26b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 18:49:17 -0700 Subject: [PATCH 5/9] Add attributes.codegen.inline.trait This adds some wording that was removed from the "optimization hints" section. --- src/attributes/codegen.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 21a28539c7..ccc9477eb7 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -62,6 +62,9 @@ There are three ways to use the inline attribute: > [!NOTE] > `#[inline]` in every form is a hint, with no *requirements* on the language to place a copy of the attributed function in the caller. +r[attributes.codegen.inline.trait] +When `inline` is applied to a function in a [trait definition], it applies only to that function when used as a default function for a trait implementation and not to all trait implementations. + r[attributes.codegen.cold] ### The `cold` attribute From c43da99890937ed0ce66c17103ba9796f204f1b4 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 18:51:01 -0700 Subject: [PATCH 6/9] Add attributes.codegen.inline.externally-exported This rule did not seem to be covered elsewhere. I'm not 100% positive this is the best way to document this, but I think it is accurate. This is implemented in https://github.com/rust-lang/rust/blob/5526a2f47cd676ceeedc08cf71ae75ce2e9284ae/compiler/rustc_passes/src/check_attr.rs#L482-L497 --- src/attributes/codegen.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index ccc9477eb7..e78309e9e2 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -65,6 +65,9 @@ There are three ways to use the inline attribute: r[attributes.codegen.inline.trait] When `inline` is applied to a function in a [trait definition], it applies only to that function when used as a default function for a trait implementation and not to all trait implementations. +r[attributes.codegen.inline.externally-exported] +The `inline` attribute is ignored if the function is externally exported. This may happen with the [`no_mangle`] or [`export_name`] attribute. + r[attributes.codegen.cold] ### The `cold` attribute From 48ffb2e929f7494caad8933e5c91d36914541a17 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 18:59:04 -0700 Subject: [PATCH 7/9] Update cold to use the attribute template --- src/attributes/codegen.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index e78309e9e2..c419d9b3d7 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -71,8 +71,42 @@ The `inline` attribute is ignored if the function is externally exported. This m r[attributes.codegen.cold] ### The `cold` attribute +r[attributes.codegen.cold.intro] The *`cold` [attribute]* suggests that the attributed function is unlikely to be called. +> [!EXAMPLE] +> ```rust +> #[cold] +> pub fn example() {} +> ``` + +r[attributes.codegen.cold.syntax] +The `cold` attribute uses the [MetaWord] syntax and thus does not take any inputs. + +r[attributes.codegen.cold.allowed-positions] +The `cold` attribute may only be used on: + +- [Free functions][items.fn] +- [Inherent associated functions][items.associated.fn] +- [Trait impl functions][items.impl.trait] +- [Trait definition functions][items.traits] with a body +- [External block functions][items.extern.fn] +- [Closures][expr.closure] + +> [!NOTE] +> `rustc` currently warns when `inline` is used in some other positions. This may become an error in the future. + + + +r[attributes.codegen.cold.duplicates] +Duplicate instances of the `cold` attribute are ignored. + +> [!NOTE] +> `rustc` currently warns on duplicate `cold` attributes. + +r[attributes.codegen.cold.trait] +When `cold` is applied to a function in a [trait definition], it applies only to that function when used as a default function for a trait implementation and not to all trait implementations. + r[attributes.codegen.naked] ## The `naked` attribute @@ -711,10 +745,12 @@ If the address of the function is taken as a function pointer, the low bit of th [`-C target-cpu`]: ../../rustc/codegen-options/index.html#target-cpu [`-C target-feature`]: ../../rustc/codegen-options/index.html#target-feature +[`export_name`]: ../abi.md#the-export_name-attribute [`is_aarch64_feature_detected`]: ../../std/arch/macro.is_aarch64_feature_detected.html [`is_x86_feature_detected`]: ../../std/arch/macro.is_x86_feature_detected.html [`Location`]: core::panic::Location [`naked_asm!`]: ../inline-assembly.md +[`no_mangle`]: ../abi.md#the-no_mangle-attribute [`target_feature` conditional compilation option]: ../conditional-compilation.md#target_feature [`unused_variables`]: ../../rustc/lints/listing/warn-by-default.html#unused-variables [attribute]: ../attributes.md @@ -724,5 +760,6 @@ If the address of the function is taken as a function pointer, the low bit of th [rust-abi]: ../items/external-blocks.md#abi [target architecture]: ../conditional-compilation.md#target_arch [trait]: ../items/traits.md +[trait definition]: ../items/traits.md [undefined behavior]: ../behavior-considered-undefined.md [unsafe attribute]: ../attributes.md#r-attributes.safety From 0f9d5924244386403c9d23c72452b974e29d231e Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Mon, 1 Sep 2025 05:30:58 +0000 Subject: [PATCH 8/9] Revise text for `inline` and `cold` Note in particular that `inline` and similar attributes can be applied to `async` blocks as well as to closures. Along with the editorial revisions, let's say that and also discuss the current limitations that affect how these can be applied. --- src/attributes/codegen.md | 89 +++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index c419d9b3d7..5c7247bf4a 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -3,11 +3,12 @@ r[attributes.codegen] The following [attributes] are used for controlling code generation. + r[attributes.codegen.inline] ### The `inline` attribute r[attributes.codegen.inline.intro] -The *`inline` [attribute]* suggests that a copy of the attributed function should be placed in the caller, rather than generating code to call the function where it is defined. +The *`inline` [attribute]* suggests whether a copy of the attributed function's code should be placed in the caller rather than generating a call to the function. > [!EXAMPLE] > ```rust @@ -22,7 +23,7 @@ The *`inline` [attribute]* suggests that a copy of the attributed function shoul > ``` > [!NOTE] -> The `rustc` compiler automatically inlines functions based on internal heuristics. Incorrectly inlining functions can make the program slower, so this attribute should be used with care. +> `rustc` automatically inlines functions when doing so seems worthwhile. Use this attribute carefully as poor decisions about what to inline can slow down programs. r[attributes.codegen.inline.syntax] The syntax for the `inline` attribute is: @@ -35,44 +36,53 @@ The syntax for the `inline` attribute is: ``` r[attributes.codegen.inline.allowed-positions] -The `inline` attribute may only be used on: +The `inline` attribute may only be applied to functions with [bodies] --- [closures], [async blocks], [free functions], [associated functions] in an [inherent impl] or [trait impl], and associated functions in a [trait definition] when those functions have a [default definition] . -- [Free functions][items.fn] -- [Inherent associated functions][items.associated.fn] -- [Trait impl functions][items.impl.trait] -- [Trait definition functions][items.traits] with a body -- [Closures][expr.closure] +> [!NOTE] +> `rustc` ignores use in other positions but lints against it. This may become an error in the future. > [!NOTE] -> `rustc` currently warns when `inline` is used in some other positions. This may become an error in the future. +> Though the attribute can be applied to [closures] and [async blocks], the usefulness of this is limited as we do not yet support attributes on expressions. +> +> ```rust +> // We allow attributes on statements. +> #[inline] || (); // OK +> #[inline] async {}; // OK +> ``` +> +> ```rust,compile_fail,E0658 +> // We don't yet allow attributes on expressions. +> let f = #[inline] || (); // ERROR +> ``` r[attributes.codegen.inline.duplicates] -Only the first instance of `inline` on an item is honored. Subsequent `inline` attributes are ignored. +Only the first use of `inline` on a function has effect. > [!NOTE] -> `rustc` currently warns on duplicate `inline` attributes. This may become an error in the future. +> `rustc` lints against any use following the first. This may become an error in the future. r[attributes.codegen.inline.modes] -There are three ways to use the inline attribute: +The `inline` attribute supports these modes: -* `#[inline]` *suggests* performing an inline expansion. -* `#[inline(always)]` *suggests* that an inline expansion should always be performed. -* `#[inline(never)]` *suggests* that an inline expansion should never be performed. +- `#[inline]` *suggests* performing inline expansion. +- `#[inline(always)]` *suggests* that inline expansion should always be performed. +- `#[inline(never)]` *suggests* that inline expansion should never be performed. > [!NOTE] -> `#[inline]` in every form is a hint, with no *requirements* on the language to place a copy of the attributed function in the caller. +> In every form the attribute is a hint. The compiler may ignore it. r[attributes.codegen.inline.trait] -When `inline` is applied to a function in a [trait definition], it applies only to that function when used as a default function for a trait implementation and not to all trait implementations. +When `inline` is applied to a function in a [trait], it applies only to the code of the [default definition]. r[attributes.codegen.inline.externally-exported] -The `inline` attribute is ignored if the function is externally exported. This may happen with the [`no_mangle`] or [`export_name`] attribute. +The `inline` attribute is ignored if the function is externally exported with [`no_mangle`] or [`export_name`]. + r[attributes.codegen.cold] ### The `cold` attribute r[attributes.codegen.cold.intro] -The *`cold` [attribute]* suggests that the attributed function is unlikely to be called. +The *`cold` [attribute]* suggests that the attributed function is unlikely to be called which may help the compiler produce better code. > [!EXAMPLE] > ```rust @@ -81,31 +91,27 @@ The *`cold` [attribute]* suggests that the attributed function is unlikely to be > ``` r[attributes.codegen.cold.syntax] -The `cold` attribute uses the [MetaWord] syntax and thus does not take any inputs. +The `cold` attribute uses the [MetaWord] syntax. r[attributes.codegen.cold.allowed-positions] -The `cold` attribute may only be used on: +The `cold` attribute may only be applied to functions with [bodies] --- [closures], [async blocks], [free functions], [associated functions] in an [inherent impl] or [trait impl], and associated functions in a [trait definition] when those functions have a [default definition] . -- [Free functions][items.fn] -- [Inherent associated functions][items.associated.fn] -- [Trait impl functions][items.impl.trait] -- [Trait definition functions][items.traits] with a body -- [External block functions][items.extern.fn] -- [Closures][expr.closure] +> [!NOTE] +> `rustc` ignores use in other positions but lints against it. This may become an error in the future. > [!NOTE] -> `rustc` currently warns when `inline` is used in some other positions. This may become an error in the future. +> Though the attribute can be applied to [closures] and [async blocks], the usefulness of this is limited as we do not yet support attributes on expressions. r[attributes.codegen.cold.duplicates] -Duplicate instances of the `cold` attribute are ignored. +Only the first use of `cold` on a function has effect. > [!NOTE] -> `rustc` currently warns on duplicate `cold` attributes. +> `rustc` lints against any use following the first. This may become an error in the future. r[attributes.codegen.cold.trait] -When `cold` is applied to a function in a [trait definition], it applies only to that function when used as a default function for a trait implementation and not to all trait implementations. +When `cold` is applied to a function in a [trait], it applies only to the code of the [default definition]. r[attributes.codegen.naked] ## The `naked` attribute @@ -716,11 +722,14 @@ r[attributes.codegen.instruction_set.syntax] The `instruction_set` attribute uses the [MetaListPaths] syntax to specify a single path consisting of the architecture family name and instruction set name. r[attributes.codegen.instruction_set.allowed-positions] -The `instruction_set` attribute may only be applied to functions, including [closures][expr.closure], [free functions][items.fn], and associated functions defined (i.e. with a body) in [inherent impls][items.associated.fn], [trait impls][items.impl.trait], and [trait definitions][items.traits]. +The `instruction_set` attribute may only be applied to functions with [bodies] --- [closures], [async blocks], [free functions], [associated functions] in an [inherent impl] or [trait impl], and associated functions in a [trait definition] when those functions have a [default definition] . > [!NOTE] > `rustc` ignores use in other positions but lints against it. This may become an error in the future. +> [!NOTE] +> Though the attribute can be applied to [closures] and [async blocks], the usefulness of this is limited as we do not yet support attributes on expressions. + r[attributes.codegen.instruction_set.duplicates] The `instruction_set` attribute may be used only once on a function. @@ -745,21 +754,29 @@ If the address of the function is taken as a function pointer, the low bit of th [`-C target-cpu`]: ../../rustc/codegen-options/index.html#target-cpu [`-C target-feature`]: ../../rustc/codegen-options/index.html#target-feature -[`export_name`]: ../abi.md#the-export_name-attribute +[`export_name`]: abi.export_name [`is_aarch64_feature_detected`]: ../../std/arch/macro.is_aarch64_feature_detected.html [`is_x86_feature_detected`]: ../../std/arch/macro.is_x86_feature_detected.html [`Location`]: core::panic::Location [`naked_asm!`]: ../inline-assembly.md -[`no_mangle`]: ../abi.md#the-no_mangle-attribute +[`no_mangle`]: abi.no_mangle [`target_feature` conditional compilation option]: ../conditional-compilation.md#target_feature [`unused_variables`]: ../../rustc/lints/listing/warn-by-default.html#unused-variables +[associated functions]: items.associated.fn +[async blocks]: expr.block.async [attribute]: ../attributes.md [attributes]: ../attributes.md +[bodies]: items.fn.body +[closures]: expr.closure +[default definition]: items.traits.associated-item-decls +[free functions]: items.fn [function body]: ../items/functions.md#function-body [functions]: ../items/functions.md +[inherent impl]: items.impl.inherent [rust-abi]: ../items/external-blocks.md#abi [target architecture]: ../conditional-compilation.md#target_arch -[trait]: ../items/traits.md -[trait definition]: ../items/traits.md +[trait]: items.traits +[trait definition]: items.traits +[trait impl]: items.impl.trait [undefined behavior]: ../behavior-considered-undefined.md [unsafe attribute]: ../attributes.md#r-attributes.safety From 80afb2e4e4f33eb30f203d9969460207ebb82178 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Wed, 3 Sep 2025 06:36:06 +0000 Subject: [PATCH 9/9] Add rule about meaning of `inline` with `async` On lang, we had earlier made a decision about how `inline` should apply to `async fn`. Let's document that here. --- src/attributes/codegen.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 5c7247bf4a..8d7948163b 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -74,6 +74,12 @@ The `inline` attribute supports these modes: r[attributes.codegen.inline.trait] When `inline` is applied to a function in a [trait], it applies only to the code of the [default definition]. +r[attributes.codegen.inline.async] +When `inline` is applied to an [async function] or [async closure], it applies only to the code of the generated `poll` function. + +> [!NOTE] +> For more details, see [Rust issue #129347](https://github.com/rust-lang/rust/issues/129347). + r[attributes.codegen.inline.externally-exported] The `inline` attribute is ignored if the function is externally exported with [`no_mangle`] or [`export_name`]. @@ -764,6 +770,8 @@ If the address of the function is taken as a function pointer, the low bit of th [`unused_variables`]: ../../rustc/lints/listing/warn-by-default.html#unused-variables [associated functions]: items.associated.fn [async blocks]: expr.block.async +[async closure]: expr.closure.async +[async function]: items.fn.async [attribute]: ../attributes.md [attributes]: ../attributes.md [bodies]: items.fn.body