@@ -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
@@ -405,25 +403,43 @@ When used on a function in an implementation, the attribute does nothing.
405
403
The `must_use ` attribute may also include a message by using
406
404
`#[must_use = " message" ]`. The message will be given alongside the warning .
407
405
408
- ### Inline attribute
406
+ ### Optimization Hints
409
407
410
- The inline attribute suggests that the compiler should place a copy of
411
- the function or static in the caller , rather than generating code to
412
- call the function or access the static where it is defined .
408
+ The ` cold ` and ` inline ` attributes give suggestions to the compiler to compile
409
+ your code in a way that may be faster than what it would do without the hint .
410
+ The attributes are only suggestions , and the compiler may choose to ignore it .
413
411
414
- The compiler automatically inlines functions based on internal heuristics .
415
- Incorrectly inlining functions can actually make the program slower , so it
416
- should be used with care .
412
+ #### `inline ` Attribute
417
413
418
- `#[inline]` and `#[inline(always)]` always cause the function to be serialized
419
- into the crate metadata to allow cross - crate inlining .
414
+ The * `inline ` attribute * suggests to the compiler that it should place a copy of
415
+ the attributed function in the caller , rather than generating code to call the
416
+ function where it is defined .
420
417
421
- There are three different types of inline attributes :
418
+ This attribute can be used on [functions ] and function prototypes , although it
419
+ does not do anything on function prototypes . When this attribute is applied to
420
+ a function in a [trait ], it applies only to that function when used as a default
421
+ function for a trait implementation and not to all trait implementations .
422
+
423
+ > ** * Note *** : The compiler automatically inlines functions based on internal
424
+ > heuristics . Incorrectly inlining functions can actually make the program
425
+ > slower , so this attibute should be used with care .
426
+
427
+ There are three ways of using the inline attribute :
422
428
423
429
* `#[inline]` hints the compiler to perform an inline expansion .
424
430
* `#[inline(always)]` asks the compiler to always perform an inline expansion .
425
431
* `#[inline(never)]` asks the compiler to never perform an inline expansion .
426
432
433
+ #### `cold ` Attribute
434
+
435
+ The * `cold ` attribute * suggests to the compiler that the attributed function is
436
+ unlikely to be called .
437
+
438
+ This attribute can be used on [functions ] and function prototypes , although it
439
+ does not do anything on function prototypes . When this attribute is applied to
440
+ a function in a [trait ], it applies only to that function when used as a default
441
+ function for a trait implementation and not to all trait implementations .
442
+
427
443
### `derive `
428
444
429
445
The `derive ` attribute allows certain traits to be automatically implemented
@@ -454,7 +470,7 @@ impl<T: PartialEq> PartialEq for Foo<T> {
454
470
}
455
471
```
456
472
457
- You can implement ` derive ` for your own type through [ procedural macros] .
473
+ You can implement ` derive ` for your own traits through [ procedural macros] .
458
474
459
475
[ Doc comments ] : comments.html#doc-comments
460
476
[ The Rustdoc Book ] : ../rustdoc/the-doc-attribute.html
@@ -482,4 +498,5 @@ You can implement `derive` for your own type through [procedural macros].
482
498
[ match expressions ] : expressions/match-expr.html
483
499
[ external blocks ] : items/external-blocks.html
484
500
[ items ] : items.html
485
- [ conditional compilation ] : conditional-compilation.html
501
+ [ conditional compilation ] : conditional-compilation.html
502
+ [ trait ] : items/traits.html
0 commit comments