2020>   ;  ; _ FunctionParam_ (` , ` _ FunctionParam_ )<sup >\* </sup > ` , ` <sup >?</sup >
2121>
2222> _ FunctionParam_ :\
23- >   ;  ; [ _ Pattern_ ] ` : ` [ _ Type_ ]
23+ >   ;  ; [ _ OuterAttribute _ ] < sup > \* </ sup > [ _ Pattern_ ] ` : ` [ _ Type_ ]
2424>
2525> _ FunctionReturnType_ :\
2626>   ;  ; ` -> ` [ _ Type_ ]
@@ -345,12 +345,40 @@ fn test_only() {
345345> Note: Except for lints, it is idiomatic to only use outer attributes on
346346> function items.
347347
348- The attributes that have meaning on a function are [ ` cfg ` ] , [ ` deprecated ` ] ,
348+ The attributes that have meaning on a function are [ ` cfg ` ] , [ ` cfg_attr ` ] , [ ` deprecated ` ] ,
349349[ ` doc ` ] , [ ` export_name ` ] , [ ` link_section ` ] , [ ` no_mangle ` ] , [ the lint check
350350attributes] , [ ` must_use ` ] , [ the procedural macro attributes] , [ the testing
351351attributes] , and [ the optimization hint attributes] . Functions also accept
352352attributes macros.
353353
354+ ## Attributes on function parameters
355+
356+ [ Outer attributes] [ attributes ] are allowed on function parameters and the
357+ permitted [ built-in attributes] are restricted to ` cfg ` , ` cfg_attr ` , ` allow ` ,
358+ ` warn ` , ` deny ` , and ` forbid ` .
359+
360+ ``` rust
361+ fn len (
362+ #[cfg (windows )] slice : & [u16 ],
363+ #[cfg (not (windows ))] slice : & [u8 ],
364+ ) -> usize {
365+ slice . len ()
366+ }
367+ ```
368+
369+ Inert helper attributes used by procedural macro attributes applied to items are also
370+ allowed but be careful to not include these inert attributes in your final ` TokenStream ` .
371+
372+ For example, the following code defines an inert ` some_inert_attribute ` attribute that
373+ is not formally defined anywhere and the ` some_proc_macro_attribute ` procedural macro is
374+ responsible for detecting its presence and removing it from the output token stream.
375+
376+ ``` rust,ignore
377+ #[some_proc_macro_attribute]
378+ fn foo_oof(#[some_inert_attribute] arg: u8) {
379+ }
380+ ```
381+
354382[ IDENTIFIER ] : ../identifiers.md
355383[ RAW_STRING_LITERAL ] : ../tokens.md#raw-string-literals
356384[ STRING_LITERAL ] : ../tokens.md#string-literals
@@ -359,6 +387,7 @@ attributes macros.
359387[ _Pattern_ ] : ../patterns.md
360388[ _Type_ ] : ../types.md#type-expressions
361389[ _WhereClause_ ] : generics.md#where-clauses
390+ [ _OuterAttribute_ ] : ../attributes.md
362391[ const context ] : ../const_eval.md#const-context
363392[ external block ] : external-blocks.md
364393[ path ] : ../paths.md
@@ -368,7 +397,8 @@ attributes macros.
368397[ *function item type* ] : ../types/function-item.md
369398[ Trait ] : traits.md
370399[ attributes ] : ../attributes.md
371- [ `cfg` ] : ../conditional-compilation.md
400+ [ `cfg` ] : ../conditional-compilation.md#the-cfg-attribute
401+ [ `cfg_attr` ] : ../conditional-compilation.md#the-cfg_attr-attribute
372402[ the lint check attributes ] : ../attributes/diagnostics.md#lint-check-attributes
373403[ the procedural macro attributes ] : ../procedural-macros.md
374404[ the testing attributes ] : ../attributes/testing.md
@@ -383,3 +413,4 @@ attributes macros.
383413[ `link_section` ] : ../abi.md#the-link_section-attribute
384414[ `no_mangle` ] : ../abi.md#the-no_mangle-attribute
385415[ external_block_abi ] : external-blocks.md#abi
416+ [ built-in attributes ] : ../attributes.html#built-in-attributes-index
0 commit comments