Skip to content

Commit 0cabd21

Browse files
committed
Attributes on functions
1 parent 13d9a03 commit 0cabd21

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

src/attributes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub mod m3 {
306306
}
307307
```
308308

309-
#### `must_use` Attribute
309+
#### `must_use`
310310

311311
The `must_use` attribute can be used on user-defined composite types
312312
([`struct`s][struct], [`enum`s][enum], and [`union`s][union]) and [functions].

src/expressions/block-expr.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let a = unsafe { f() };
6262
Block expressions allow [outer attributes] and [inner attributes] directly after
6363
the opening brace when the block expression is the outer expression of an
6464
[expression statement] or the final expression of another block expression. The
65-
attributes that have meaning on a block expression are [`cfg`], and [the lint
65+
attributes that have meaning on a block expression are [`cfg`] and [the lint
6666
check attributes].
6767

6868
For example, this function returns `true` on unix platforms and `false` on other
@@ -84,5 +84,5 @@ fn is_unix_platform() -> bool {
8484
[outer attributes]: attributes.html
8585
[inner attributes]: attributes.html
8686
[expression statement]: statements.html#expression-statements
87-
[`cfg`]: attributes.html#conditional-compilation
87+
[`cfg`]: conditional-compilation.html
8888
[the lint check attributes]: attributes.html#lint-check-attributes

src/expressions/match-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,6 @@ meaning on match arms are [`cfg`], `cold`, and the [lint check attributes].
209209
[numeric types]: types.html#numeric-types
210210
[_InnerAttribute_]: attributes.html
211211
[_OuterAttribute_]: attributes.html
212-
[`cfg`]: attributes.html#conditional-compilation
212+
[`cfg`]: conditional-compilation.html
213213
[lint check attributes]: attributes.html#lint-check-attributes
214214
[range]: expressions/range-expr.html

src/items/functions.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ As non-Rust calling conventions do not support unwinding, unwinding past the end
115115
of an extern function will cause the process to abort. In LLVM, this is
116116
implemented by executing an illegal instruction.
117117

118-
## Function attributes
118+
## Attributes on functions
119119

120-
Inner [attributes] on the function's block apply to the function item as a whole.
120+
Functions allow for [outer attributes][attributes] and for [inner
121+
attributes][attributes] where inner attributes are allowed on its [block].
121122

122-
For example, this function will only be available while running tests.
123+
For example of an inner attribute on a function, this function will only be
124+
available while running tests.
123125

124126
```
125127
fn test_only() {
@@ -130,6 +132,11 @@ fn test_only() {
130132
> Note: Except for lints, it is idiomatic to only use outer attributes on
131133
> function items.
132134
135+
The attributes that have meaning on a function are [`cfg`], [`deprecated`],
136+
[`doc`], `export_name`, `link_section`, `no_mangle`, [the lint check
137+
attributes], [`must_use`], [the testing attributes], and [the optimization hint
138+
attributes].
139+
133140
[external blocks]: items/external-blocks.html
134141
[path]: paths.html
135142
[block]: expressions/block-expr.html
@@ -138,3 +145,10 @@ fn test_only() {
138145
[*function item type*]: types.html#function-item-types
139146
[Trait]: items/traits.html
140147
[attributes]: attributes.html
148+
[`cfg`]: conditional-compilation.html
149+
[the lint check attributes]: attributes.html#lint-check-attributes
150+
[the testing attributes]: attributes.html#testing
151+
[the optimization hint attributes]: attributes.html#optimization-hints
152+
[`deprecated`]: attributes.html#deprecation
153+
[`doc`]: attributes.html#documentation
154+
[`must_use`]: attributes.html#must_use

src/items/implementations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ attributes].
146146

147147
[trait]: items/traits.html
148148
[attributes]: attributes.html
149-
[`cfg`]: attributes.html#conditional-compilation
149+
[`cfg`]: conditional-compilation.html
150150
[`deprecated`]: attributes.html#deprecation
151151
[`doc`]: attributes.html#documentation
152152
[the lint check attributes]: attributes.html#lint-check-attributes

src/statements.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ statement are [`cfg`], and [the lint check attributes].
104104
[implementations]: items/implementations.html
105105
[variables]: variables.html
106106
[outer attributes]: attributes.html
107-
[`cfg`]: attributes.html#conditional-compilation
107+
[`cfg`]: conditional-compilation.html
108108
[the lint check attributes]: attributes.html#lint-check-attributes

0 commit comments

Comments
 (0)