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_ ]
@@ -244,12 +244,36 @@ fn test_only() {
244
244
> Note: Except for lints, it is idiomatic to only use outer attributes on
245
245
> function items.
246
246
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 ` ] ,
248
248
[ ` doc ` ] , [ ` export_name ` ] , [ ` link_section ` ] , [ ` no_mangle ` ] , [ the lint check
249
249
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 ` .
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
+
253
277
[ IDENTIFIER ] : ../identifiers.md
254
278
[ RAW_STRING_LITERAL ] : ../tokens.md#raw-string-literals
255
279
[ STRING_LITERAL ] : ../tokens.md#string-literals
@@ -258,6 +282,7 @@ attributes macros.
258
282
[ _Pattern_ ] : ../patterns.md
259
283
[ _Type_ ] : ../types.md#type-expressions
260
284
[ _WhereClause_ ] : generics.md#where-clauses
285
+ [ _OuterAttribute_ ] : ../attributes.md
261
286
[ const context ] : ../const_eval.md#const-context
262
287
[ external blocks ] : external-blocks.md
263
288
[ path ] : ../paths.md
@@ -267,7 +292,8 @@ attributes macros.
267
292
[ *function item type* ] : ../types/function-item.md
268
293
[ Trait ] : traits.md
269
294
[ 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
271
297
[ the lint check attributes ] : ../attributes/diagnostics.md#lint-check-attributes
272
298
[ the procedural macro attributes ] : ../procedural-macros.md
273
299
[ the testing attributes ] : ../attributes/testing.md
@@ -282,3 +308,4 @@ attributes macros.
282
308
[ `link_section` ] : ../abi.md#the-link_section-attribute
283
309
[ `no_mangle` ] : ../abi.md#the-no_mangle-attribute
284
310
[ external_block_abi ] : external-blocks.md#abi
311
+ [ built-in attributes ] : ../attributes.html#built-in-attributes-index
0 commit comments