@@ -126,8 +126,6 @@ names have meaning.
126
126
- ` ignore ` - indicates that this test function is disabled.
127
127
- ` should_panic ` - indicates that this test function should panic, inverting the
128
128
success condition.
129
- - ` cold ` - The function is unlikely to be executed, so optimize it (and calls
130
- to it) differently.
131
129
132
130
## FFI attributes
133
131
@@ -495,25 +493,43 @@ When used on a function in an implementation, the attribute does nothing.
495
493
The `must_use ` attribute may also include a message by using
496
494
`#[must_use = " message" ]`. The message will be given alongside the warning .
497
495
498
- ### Inline attribute
496
+ ### Optimization Hints
499
497
500
- The inline attribute suggests that the compiler should place a copy of
501
- the function or static in the caller , rather than generating code to
502
- call the function or access the static where it is defined .
498
+ The ` cold ` and ` inline ` attributes give suggestions to the compiler to compile
499
+ your code in a way that may be faster than what it would do without the hint .
500
+ The attributes are only suggestions , and the compiler may choose to ignore it .
503
501
504
- The compiler automatically inlines functions based on internal heuristics .
505
- Incorrectly inlining functions can actually make the program slower , so it
506
- should be used with care .
502
+ #### `inline ` Attribute
507
503
508
- `#[inline]` and `#[inline(always)]` always cause the function to be serialized
509
- into the crate metadata to allow cross - crate inlining .
504
+ The * `inline ` attribute * suggests to the compiler that it should place a copy of
505
+ the attributed function in the caller , rather than generating code to call the
506
+ function where it is defined .
510
507
511
- There are three different types of inline attributes :
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
+
513
+ > ** * Note *** : The compiler automatically inlines functions based on internal
514
+ > heuristics . Incorrectly inlining functions can actually make the program
515
+ > slower , so this attibute should be used with care .
516
+
517
+ There are three ways of using the inline attribute :
512
518
513
519
* `#[inline]` hints the compiler to perform an inline expansion .
514
520
* `#[inline(always)]` asks the compiler to always perform an inline expansion .
515
521
* `#[inline(never)]` asks the compiler to never perform an inline expansion .
516
522
523
+ #### `cold ` Attribute
524
+
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 .
532
+
517
533
### `derive `
518
534
519
535
The `derive ` attribute allows certain traits to be automatically implemented
@@ -544,7 +560,7 @@ impl<T: PartialEq> PartialEq for Foo<T> {
544
560
}
545
561
```
546
562
547
- You can implement ` derive ` for your own type through [ procedural macros] .
563
+ You can implement ` derive ` for your own traits through [ procedural macros] .
548
564
549
565
[ Doc comments ] : comments.html#doc-comments
550
566
[ The Rustdoc Book ] : ../rustdoc/the-doc-attribute.html
@@ -570,4 +586,5 @@ You can implement `derive` for your own type through [procedural macros].
570
586
[ modules ] : items/modules.html
571
587
[ statements ] : statements.html
572
588
[ match expressions ] : expressions/match-expr.html
573
- [ external blocks ] : items/external-blocks.html
589
+ [ external blocks ] : items/external-blocks.html
590
+ [ trait ] : items/traits.html
0 commit comments