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,36 @@ 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 ` .
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+
268+ Inert helper attributes used by procedural macro attributes applied to items are also
269+ allowed but be careful to not include these inert attributes in your final ` TokenStream ` .
270+
271+ ``` rust
272+ #[hi_i_am_a_proc_macro_attribute]
273+ fn foo_oof (#[hello_i_am_an_inert_attribute ] arg : u8 ) {
274+ }
275+ ```
276+
253277[ IDENTIFIER ] : ../identifiers.md
254278[ RAW_STRING_LITERAL ] : ../tokens.md#raw-string-literals
255279[ STRING_LITERAL ] : ../tokens.md#string-literals
@@ -258,6 +282,7 @@ attributes macros.
258282[ _Pattern_ ] : ../patterns.md
259283[ _Type_ ] : ../types.md#type-expressions
260284[ _WhereClause_ ] : generics.md#where-clauses
285+ [ _OuterAttribute_ ] : ../attributes.md
261286[ const context ] : ../const_eval.md#const-context
262287[ external blocks ] : external-blocks.md
263288[ path ] : ../paths.md
@@ -267,7 +292,8 @@ attributes macros.
267292[ *function item type* ] : ../types/function-item.md
268293[ Trait ] : traits.md
269294[ attributes ] : ../attributes.md
270- [ `cfg` ] : ../conditional-compilation.md
295+ [ `cfg` ] : ../conditional-compilation.md#the-cfg-attribute
296+ [ `cfg_attr` ] : ../conditional-compilation.md#the-cfg_attr-attribute
271297[ the lint check attributes ] : ../attributes/diagnostics.md#lint-check-attributes
272298[ the procedural macro attributes ] : ../procedural-macros.md
273299[ the testing attributes ] : ../attributes/testing.md
@@ -282,3 +308,4 @@ attributes macros.
282308[ `link_section` ] : ../abi.md#the-link_section-attribute
283309[ `no_mangle` ] : ../abi.md#the-no_mangle-attribute
284310[ external_block_abi ] : external-blocks.md#abi
311+ [ built-in attributes ] : ../attributes.html#built-in-attributes-index
0 commit comments