|
17 | 17 | > _FunctionParam_ (`,` _FunctionParam_)<sup>\*</sup> `,`<sup>?</sup>
|
18 | 18 | >
|
19 | 19 | > _FunctionParam_ :\
|
20 |
| -> [_Pattern_] `:` [_Type_] |
| 20 | +> [_OuterAttribute_]<sup>\*</sup>\ [_Pattern_] `:` [_Type_] |
21 | 21 | >
|
22 | 22 | > _FunctionReturnType_ :\
|
23 | 23 | > `->` [_Type_]
|
@@ -250,6 +250,21 @@ attributes], [`must_use`], [the procedural macro attributes], [the testing
|
250 | 250 | attributes], and [the optimization hint attributes]. Functions also accept
|
251 | 251 | attributes macros.
|
252 | 252 |
|
| 253 | +## Attributes on function parameters |
| 254 | + |
| 255 | +[Outer attributes][attributes] are allowed on function parameters and the |
| 256 | +permitted [built-in attributes] are restricted to `cfg`, `cfg_attr`, `allow`, |
| 257 | +`warn`, `deny`, and `forbid`. For example: |
| 258 | + |
| 259 | +```rust |
| 260 | +fn len( |
| 261 | + #[cfg(windows)] slice: &[u16], |
| 262 | + #[cfg(not(windows))] slice: &[u8], |
| 263 | +) -> usize { |
| 264 | + slice.len() |
| 265 | +} |
| 266 | +``` |
| 267 | + |
253 | 268 | [IDENTIFIER]: ../identifiers.md
|
254 | 269 | [RAW_STRING_LITERAL]: ../tokens.md#raw-string-literals
|
255 | 270 | [STRING_LITERAL]: ../tokens.md#string-literals
|
@@ -282,3 +297,5 @@ attributes macros.
|
282 | 297 | [`link_section`]: ../abi.md#the-link_section-attribute
|
283 | 298 | [`no_mangle`]: ../abi.md#the-no_mangle-attribute
|
284 | 299 | [external_block_abi]: external-blocks.md#abi
|
| 300 | +[_OuterAttribute_]: ../attributes.md |
| 301 | +[built-in attributes]: ../attributes.html#built-in-attributes-index |
0 commit comments