Skip to content

Commit 0ec305b

Browse files
Mention #[cold] and #[inline] working on closures
1 parent daaa103 commit 0ec305b

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/attributes.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,17 @@ The `cold` and `inline` attributes give suggestions to the compiler to compile
499499
your code in a way that may be faster than what it would do without the hint.
500500
The attributes are only suggestions, and the compiler may choose to ignore it.
501501
502+
Both attributes can be used on closures, [functions] and function prototypes,
503+
although they do not do anything on function prototypes. When applied to a
504+
function in a [trait], they apply only to that function when used as a default
505+
function for a trait implementation and not to all trait implementations.
506+
502507
#### `inline` Attribute
503508
504509
The *`inline` attribute* suggests to the compiler that it should place a copy of
505510
the attributed function in the caller, rather than generating code to call the
506511
function where it is defined.
507512
508-
This attribute can be used on [functions] and function prototypes, although it
509-
does not do anything on function prototypes. When this attribute is applied to
510-
a function in a [trait], it applies only to that function when used as a default
511-
function for a trait implementation and not to all trait implementations.
512-
513513
> ***Note***: The compiler automatically inlines functions based on internal
514514
> heuristics. Incorrectly inlining functions can actually make the program
515515
> slower, so this attribute should be used with care.
@@ -522,13 +522,8 @@ There are three ways of using the inline attribute:
522522
523523
#### `cold` Attribute
524524
525-
The *`cold` attribute* suggests to the compiler that the attributed function is
526-
unlikely to be called.
527-
528-
This attribute can be used on [functions] and function prototypes, although it
529-
does not do anything on function prototypes. When this attribute is applied to
530-
a function in a [trait], it applies only to that function when used as a default
531-
function for a trait implementation and not to all trait implementations.
525+
The *`cold` attribute* suggests to the compiler that the attributed function or
526+
closure is unlikely to be called.
532527
533528
### `derive`
534529

0 commit comments

Comments
 (0)