@@ -71,8 +71,42 @@ The `inline` attribute is ignored if the function is externally exported. This m
7171r[ attributes.codegen.cold]
7272### The ` cold ` attribute
7373
74+ r[ attributes.codegen.cold.intro]
7475The * ` cold ` [ attribute] * suggests that the attributed function is unlikely to be called.
7576
77+ > [ !EXAMPLE]
78+ > ``` rust
79+ > #[cold]
80+ > pub fn example () {}
81+ > ```
82+
83+ r [attributes . codegen. cold. syntax]
84+ The `cold ` attribute uses the [MetaWord ] syntax and thus does not take any inputs .
85+
86+ r [attributes . codegen. cold. allowed- positions ]
87+ The `cold ` attribute may only be used on :
88+
89+ - [Free functions ][items . fn ]
90+ - [Inherent associated functions ][items . associated. fn ]
91+ - [Trait impl functions ][items . impl . trait ]
92+ - [Trait definition functions ][items . traits] with a body
93+ - [External block functions ][items . extern . fn ]
94+ - [Closures ][expr . closure]
95+
96+ > [! NOTE ]
97+ > `rustc ` currently warns when `inline ` is used in some other positions . This may become an error in the future .
98+
99+ <! -- 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 ). - ->
100+
101+ r [attributes . codegen. cold. duplicates]
102+ Duplicate instances of the `cold ` attribute are ignored .
103+
104+ > [! NOTE ]
105+ > `rustc ` currently warns on duplicate `cold ` attributes .
106+
107+ r [attributes . codegen. cold. trait ]
108+ When `cold ` is applied to a function in a [trait definition ], it applies only to that function when used as a default function for a trait implementation and not to all trait implementations .
109+
76110r [attributes . codegen. naked]
77111## The `naked ` attribute
78112
@@ -711,10 +745,12 @@ If the address of the function is taken as a function pointer, the low bit of th
711745
712746[`-C target-cpu`]: ../../rustc/codegen-options/index.html#target-cpu
713747[`-C target-feature`]: ../../rustc/codegen-options/index.html#target-feature
748+ [`export_name`]: ../abi.md#the-export_name-attribute
714749[`is_aarch64_feature_detected`]: ../../std/arch/macro.is_aarch64_feature_detected.html
715750[`is_x86_feature_detected`]: ../../std/arch/macro.is_x86_feature_detected.html
716751[`Location`]: core::panic::Location
717752[`naked_asm!`]: ../inline-assembly.md
753+ [`no_mangle`]: ../abi.md#the-no_mangle-attribute
718754[`target_feature` conditional compilation option]: ../conditional-compilation.md#target_feature
719755[`unused_variables`]: ../../rustc/lints/listing/warn-by-default.html#unused-variables
720756[attribute]: ../attributes.md
@@ -724,5 +760,6 @@ If the address of the function is taken as a function pointer, the low bit of th
724760[rust-abi]: ../items/external-blocks.md#abi
725761[target architecture]: ../conditional-compilation.md#target_arch
726762[trait]: ../items/traits.md
763+ [trait definition]: ../items/traits.md
727764[undefined behavior]: ../behavior-considered-undefined.md
728765[unsafe attribute]: ../attributes.md#r-attributes.safety
0 commit comments