Skip to content

Commit cd192bf

Browse files
Merge pull request #469 from jonas-schievink/coldness-be-my-god
Mention that #[cold] and #[inline] work on closures
2 parents 60077ef + 0ec305b commit cd192bf

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
@@ -494,17 +494,17 @@ The `cold` and `inline` attributes give suggestions to the compiler to compile
494494
your code in a way that may be faster than what it would do without the hint.
495495
The attributes are only suggestions, and the compiler may choose to ignore it.
496496
497+
Both attributes can be used on closures, [functions] and function prototypes,
498+
although they do not do anything on function prototypes. When applied to a
499+
function in a [trait], they apply only to that function when used as a default
500+
function for a trait implementation and not to all trait implementations.
501+
497502
#### `inline` Attribute
498503
499504
The *`inline` attribute* suggests to the compiler that it should place a copy of
500505
the attributed function in the caller, rather than generating code to call the
501506
function where it is defined.
502507
503-
This attribute can be used on [functions] and function prototypes, although it
504-
does not do anything on function prototypes. When this attribute is applied to
505-
a function in a [trait], it applies only to that function when used as a default
506-
function for a trait implementation and not to all trait implementations.
507-
508508
> ***Note***: The compiler automatically inlines functions based on internal
509509
> heuristics. Incorrectly inlining functions can actually make the program
510510
> slower, so this attribute should be used with care.
@@ -517,13 +517,8 @@ There are three ways of using the inline attribute:
517517
518518
#### `cold` Attribute
519519
520-
The *`cold` attribute* suggests to the compiler that the attributed function is
521-
unlikely to be called.
522-
523-
This attribute can be used on [functions] and function prototypes, although it
524-
does not do anything on function prototypes. When this attribute is applied to
525-
a function in a [trait], it applies only to that function when used as a default
526-
function for a trait implementation and not to all trait implementations.
520+
The *`cold` attribute* suggests to the compiler that the attributed function or
521+
closure is unlikely to be called.
527522
528523
### `derive`
529524

0 commit comments

Comments
 (0)