Skip to content

Commit

Permalink
Merge pull request rust-lang#387 from Havvy/attr-on-fns
Browse files Browse the repository at this point in the history
Attributes on functions
  • Loading branch information
matthewjasper authored Sep 2, 2018
2 parents dc56e79 + ad7526f commit a35793c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ pub mod m3 {
}
```

#### `must_use` Attribute
#### `must_use`

The `must_use` attribute can be used on user-defined composite types
([`struct`s][struct], [`enum`s][enum], and [`union`s][union]) and [functions].
Expand Down
4 changes: 2 additions & 2 deletions src/expressions/block-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let a = unsafe { an_unsafe_fn() };
Block expressions allow [outer attributes] and [inner attributes] directly after
the opening brace when the block expression is the outer expression of an
[expression statement] or the final expression of another block expression. The
attributes that have meaning on a block expression are [`cfg`], and [the lint
attributes that have meaning on a block expression are [`cfg`] and [the lint
check attributes].

For example, this function returns `true` on unix platforms and `false` on other
Expand All @@ -136,6 +136,6 @@ fn is_unix_platform() -> bool {
[outer attributes]: attributes.html
[inner attributes]: attributes.html
[expression statement]: statements.html#expression-statements
[`cfg`]: attributes.html#conditional-compilation
[`cfg`]: conditional-compilation.html
[the lint check attributes]: attributes.html#lint-check-attributes
[unsafe operations]: unsafety.html
2 changes: 1 addition & 1 deletion src/expressions/match-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ meaning on match arms are [`cfg`], `cold`, and the [lint check attributes].
[numeric types]: types.html#numeric-types
[_InnerAttribute_]: attributes.html
[_OuterAttribute_]: attributes.html
[`cfg`]: attributes.html#conditional-compilation
[`cfg`]: conditional-compilation.html
[lint check attributes]: attributes.html#lint-check-attributes
[range]: expressions/range-expr.html
20 changes: 17 additions & 3 deletions src/items/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ As non-Rust calling conventions do not support unwinding, unwinding past the end
of an extern function will cause the process to abort. In LLVM, this is
implemented by executing an illegal instruction.

## Function attributes
## Attributes on functions

Inner [attributes] on the function's block apply to the function item as a whole.
[Outer attributes][attributes] are allowed on functions. [Inner
attributes][attributes] are allowed directly after the `{` inside its [block].

For example, this function will only be available while running tests.
This example shows an inner attribute on a function. The function will only be
available while running tests.

```
fn test_only() {
Expand All @@ -130,6 +132,11 @@ fn test_only() {
> Note: Except for lints, it is idiomatic to only use outer attributes on
> function items.
The attributes that have meaning on a function are [`cfg`], [`deprecated`],
[`doc`], `export_name`, `link_section`, `no_mangle`, [the lint check
attributes], [`must_use`], [the testing attributes], and [the optimization hint
attributes].

[external blocks]: items/external-blocks.html
[path]: paths.html
[block]: expressions/block-expr.html
Expand All @@ -138,3 +145,10 @@ fn test_only() {
[*function item type*]: types.html#function-item-types
[Trait]: items/traits.html
[attributes]: attributes.html
[`cfg`]: conditional-compilation.html
[the lint check attributes]: attributes.html#lint-check-attributes
[the testing attributes]: attributes.html#testing
[the optimization hint attributes]: attributes.html#optimization-hints
[`deprecated`]: attributes.html#deprecation
[`doc`]: attributes.html#documentation
[`must_use`]: attributes.html#must_use
2 changes: 1 addition & 1 deletion src/items/implementations.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ attributes].

[trait]: items/traits.html
[attributes]: attributes.html
[`cfg`]: attributes.html#conditional-compilation
[`cfg`]: conditional-compilation.html
[`deprecated`]: attributes.html#deprecation
[`doc`]: attributes.html#documentation
[the lint check attributes]: attributes.html#lint-check-attributes
2 changes: 1 addition & 1 deletion src/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ statement are [`cfg`], and [the lint check attributes].
[implementations]: items/implementations.html
[variables]: variables.html
[outer attributes]: attributes.html
[`cfg`]: attributes.html#conditional-compilation
[`cfg`]: conditional-compilation.html
[the lint check attributes]: attributes.html#lint-check-attributes

0 comments on commit a35793c

Please sign in to comment.