Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/attributes/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ The `inline` attribute may only be applied to functions with [bodies] --- [closu
> `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.
> Attributes are supported on closure expressions, but remain restricted on other
> expressions such as [async blocks].
>
> ```rust
> // We allow attributes on statements.
> #[inline] || (); // OK
> #[inline] async {}; // OK
> ```
> let f = #[inline] || (); // OK
>
> ```rust,compile_fail,E0658
> // We don't yet allow attributes on expressions.
> let f = #[inline] || (); // ERROR
> // We also allow attributes on statements.
> #[inline] async {}; // OK
> ```

r[attributes.codegen.inline.duplicates]
Expand Down Expand Up @@ -106,7 +103,8 @@ The `cold` attribute may only be applied to functions with [bodies] --- [closure
> `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.
> Attributes are supported on closure expressions, but remain restricted on other
> expressions such as [async blocks].

<!-- TODO: rustc currently seems to allow cold on a trait function without a body, but it appears to be ignored. I think that may be a bug, and it should at least warn if not reject (like inline does). -->

Expand Down Expand Up @@ -872,7 +870,8 @@ The `instruction_set` attribute may only be applied to functions with [bodies] -
> `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.
> Attributes are supported on closure expressions, but remain restricted on other
> expressions such as [async blocks].

r[attributes.codegen.instruction_set.duplicates]
The `instruction_set` attribute may be used only once on a function.
Expand Down
5 changes: 5 additions & 0 deletions src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ r[expr.attr.restriction]
* Before an expression used as a [statement].
* Elements of [array expressions], [tuple expressions], [call expressions], and tuple-style [struct] expressions.
* The tail expression of [block expressions].
* Before [closure expressions] and [method-call expressions]. An attribute before a
method-call expression applies to the complete method-call expression, including
any chained method calls.
<!-- Keep list in sync with block-expr.md -->

r[expr.attr.never-before]
Expand All @@ -385,6 +388,7 @@ They are never allowed before:
[borrow]: expressions/operator-expr.md#borrow-operators
[call expressions]: expressions/call-expr.md
[comparison]: expressions/operator-expr.md#comparison-operators
[closure expressions]: expressions/closure-expr.md
[compound assignment]: expressions/operator-expr.md#compound-assignment-expressions
[deref]: expressions/operator-expr.md#the-dereference-operator
[destructors]: destructors.md
Expand All @@ -403,6 +407,7 @@ They are never allowed before:
[macro invocations]: macro.invocation
[match]: expressions/match-expr.md
[method-call]: expressions/method-call-expr.md
[method-call expressions]: expressions/method-call-expr.md
[Mutable `static` items]: items/static-items.md#mutable-statics
[Outer attributes]: attributes.md
[paths]: expressions/path-expr.md
Expand Down
Loading