Skip to content

Commit a35793c

Browse files
Merge pull request #387 from Havvy/attr-on-fns
Attributes on functions
2 parents dc56e79 + ad7526f commit a35793c

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
@@ -331,7 +331,7 @@ pub mod m3 {
331331
}
332332
```
333333

334-
#### `must_use` Attribute
334+
#### `must_use`
335335

336336
The `must_use` attribute can be used on user-defined composite types
337337
([`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
@@ -112,7 +112,7 @@ let a = unsafe { an_unsafe_fn() };
112112
Block expressions allow [outer attributes] and [inner attributes] directly after
113113
the opening brace when the block expression is the outer expression of an
114114
[expression statement] or the final expression of another block expression. The
115-
attributes that have meaning on a block expression are [`cfg`], and [the lint
115+
attributes that have meaning on a block expression are [`cfg`] and [the lint
116116
check attributes].
117117

118118
For example, this function returns `true` on unix platforms and `false` on other
@@ -136,6 +136,6 @@ fn is_unix_platform() -> bool {
136136
[outer attributes]: attributes.html
137137
[inner attributes]: attributes.html
138138
[expression statement]: statements.html#expression-statements
139-
[`cfg`]: attributes.html#conditional-compilation
139+
[`cfg`]: conditional-compilation.html
140140
[the lint check attributes]: attributes.html#lint-check-attributes
141141
[unsafe operations]: unsafety.html

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+
[Outer attributes][attributes] are allowed on functions. [Inner
121+
attributes][attributes] are allowed directly after the `{` inside its [block].
121122

122-
For example, this function will only be available while running tests.
123+
This example shows an inner attribute on a function. The 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
@@ -145,7 +145,7 @@ attributes].
145145

146146
[trait]: items/traits.html
147147
[attributes]: attributes.html
148-
[`cfg`]: attributes.html#conditional-compilation
148+
[`cfg`]: conditional-compilation.html
149149
[`deprecated`]: attributes.html#deprecation
150150
[`doc`]: attributes.html#documentation
151151
[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)