1717>   ;  ; _ FunctionParam_ (` , ` _ FunctionParam_ )<sup >\* </sup > ` , ` <sup >?</sup >
1818>
1919> _ FunctionParam_ :\
20- >   ;  ; [ _ Pattern_ ] ` : ` [ _ Type_ ]
20+ >   ;  ; [ _ OuterAttribute _ ] < sup > \* </ sup >\ [ _ Pattern_ ] ` : ` [ _ Type_ ]
2121>
2222> _ FunctionReturnType_ :\
2323>   ;  ; ` -> ` [ _ Type_ ]
@@ -244,12 +244,27 @@ fn test_only() {
244244> Note: Except for lints, it is idiomatic to only use outer attributes on
245245> function items.
246246
247- The attributes that have meaning on a function are [ ` cfg ` ] , [ ` deprecated ` ] ,
247+ The attributes that have meaning on a function are [ ` cfg ` ] , [ ` cfg_attr ` ] , [ ` deprecated ` ] ,
248248[ ` doc ` ] , [ ` export_name ` ] , [ ` link_section ` ] , [ ` no_mangle ` ] , [ the lint check
249249attributes] , [ ` must_use ` ] , [ the procedural macro attributes] , [ the testing
250250attributes] , and [ the optimization hint attributes] . Functions also accept
251251attributes macros.
252252
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+
253268[ IDENTIFIER ] : ../identifiers.md
254269[ RAW_STRING_LITERAL ] : ../tokens.md#raw-string-literals
255270[ STRING_LITERAL ] : ../tokens.md#string-literals
@@ -258,6 +273,7 @@ attributes macros.
258273[ _Pattern_ ] : ../patterns.md
259274[ _Type_ ] : ../types.md#type-expressions
260275[ _WhereClause_ ] : generics.md#where-clauses
276+ [ _OuterAttribute_ ] : ../attributes.md
261277[ const context ] : ../const_eval.md#const-context
262278[ external blocks ] : external-blocks.md
263279[ path ] : ../paths.md
@@ -267,7 +283,8 @@ attributes macros.
267283[ *function item type* ] : ../types/function-item.md
268284[ Trait ] : traits.md
269285[ attributes ] : ../attributes.md
270- [ `cfg` ] : ../conditional-compilation.md
286+ [ `cfg` ] : ../conditional-compilation.md#the-cfg-attribute
287+ [ `cfg_attr` ] : ../conditional-compilation.md#the-cfg_attr-attribute
271288[ the lint check attributes ] : ../attributes/diagnostics.md#lint-check-attributes
272289[ the procedural macro attributes ] : ../procedural-macros.md
273290[ the testing attributes ] : ../attributes/testing.md
@@ -282,3 +299,4 @@ attributes macros.
282299[ `link_section` ] : ../abi.md#the-link_section-attribute
283300[ `no_mangle` ] : ../abi.md#the-no_mangle-attribute
284301[ external_block_abi ] : external-blocks.md#abi
302+ [ built-in attributes ] : ../attributes.html#built-in-attributes-index
0 commit comments