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,27 @@ 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 ` . 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
@@ -258,6 +273,7 @@ attributes macros.
258
273
[ _Pattern_ ] : ../patterns.md
259
274
[ _Type_ ] : ../types.md#type-expressions
260
275
[ _WhereClause_ ] : generics.md#where-clauses
276
+ [ _OuterAttribute_ ] : ../attributes.md
261
277
[ const context ] : ../const_eval.md#const-context
262
278
[ external blocks ] : external-blocks.md
263
279
[ path ] : ../paths.md
@@ -267,7 +283,8 @@ attributes macros.
267
283
[ *function item type* ] : ../types/function-item.md
268
284
[ Trait ] : traits.md
269
285
[ 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
271
288
[ the lint check attributes ] : ../attributes/diagnostics.md#lint-check-attributes
272
289
[ the procedural macro attributes ] : ../procedural-macros.md
273
290
[ the testing attributes ] : ../attributes/testing.md
@@ -282,3 +299,4 @@ attributes macros.
282
299
[ `link_section` ] : ../abi.md#the-link_section-attribute
283
300
[ `no_mangle` ] : ../abi.md#the-no_mangle-attribute
284
301
[ external_block_abi ] : external-blocks.md#abi
302
+ [ built-in attributes ] : ../attributes.html#built-in-attributes-index
0 commit comments