From 84098acc76ded99cecce31b77bbd81f381aa97a5 Mon Sep 17 00:00:00 2001 From: Havvy Date: Fri, 3 Aug 2018 14:02:56 -0700 Subject: [PATCH 1/2] Attributes on functions --- src/attributes.md | 2 +- src/expressions/block-expr.md | 4 ++-- src/expressions/match-expr.md | 2 +- src/items/functions.md | 20 +++++++++++++++++--- src/items/implementations.md | 2 +- src/statements.md | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/attributes.md b/src/attributes.md index 913a63f5a..ccb7bca64 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -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]. diff --git a/src/expressions/block-expr.md b/src/expressions/block-expr.md index 2610b2aa6..3778aba75 100644 --- a/src/expressions/block-expr.md +++ b/src/expressions/block-expr.md @@ -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 @@ -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 diff --git a/src/expressions/match-expr.md b/src/expressions/match-expr.md index 3464c0ac2..5dd683102 100644 --- a/src/expressions/match-expr.md +++ b/src/expressions/match-expr.md @@ -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 diff --git a/src/items/functions.md b/src/items/functions.md index a3252add2..7a83ae112 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -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. +Functions allow for [outer attributes][attributes] and for [inner +attributes][attributes] where inner attributes are allowed on its [block]. -For example, this function will only be available while running tests. +For example of an inner attribute on a function, this function will only be +available while running tests. ``` fn test_only() { @@ -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 @@ -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 \ No newline at end of file diff --git a/src/items/implementations.md b/src/items/implementations.md index 8b11d0536..09b38406f 100644 --- a/src/items/implementations.md +++ b/src/items/implementations.md @@ -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 diff --git a/src/statements.md b/src/statements.md index bbe83d375..52c78ba13 100644 --- a/src/statements.md +++ b/src/statements.md @@ -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 From ad7526f7f91e19852535d0c00ef8b85922543dda Mon Sep 17 00:00:00 2001 From: "Havvy (Ryan Scheel)" Date: Sat, 1 Sep 2018 23:35:54 -0700 Subject: [PATCH 2/2] Verbiage suggestions from review --- src/items/functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/items/functions.md b/src/items/functions.md index 7a83ae112..fab09563b 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -117,10 +117,10 @@ implemented by executing an illegal instruction. ## Attributes on functions -Functions allow for [outer attributes][attributes] and for [inner -attributes][attributes] where inner attributes are allowed on its [block]. +[Outer attributes][attributes] are allowed on functions. [Inner +attributes][attributes] are allowed directly after the `{` inside its [block]. -For example of an inner attribute on a function, this function will only be +This example shows an inner attribute on a function. The function will only be available while running tests. ```