Skip to content

Commit d4ff544

Browse files
committed
rfc/param-attrs: clarify grammar.
1 parent 009286d commit d4ff544

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

text/2540-formal-function-parameter-attributes.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ fn foo(#[inline] bar: u32) { .. }
315315
Let `OuterAttr` denote the production for an attribute `#[...]`.
316316

317317
On the formal parameters of an `fn` item, including on method receivers,
318-
and irrespective of whether the `fn` has a body or not, `OuterAttr+` is allowed.
319-
For example, all the following are valid:
318+
and irrespective of whether the `fn` has a body or not, `OuterAttr+` is allowed
319+
but not required. For example, all the following are valid:
320320

321321
```rust
322322
fn g1(#[attr1] #[attr2] pat: Type) { .. }
@@ -334,11 +334,17 @@ fn g6<'a>(#[attr] &'a self) { .. }
334334
fn g7<'a>(#[attr] &'a mut self) { .. }
335335

336336
fn g8(#[attr] self: Self) { .. }
337+
338+
fn g9(#[attr] self: Rc<Self>) { .. }
337339
```
338340

339341
The attributes here apply to the parameter *as a whole*,
340342
e.g. in `g2`, `#[attr]` applies to `pat: Type` as opposed to `pat`.
341343

344+
More generally, an `fn` item contains a list of formal parameters separated or
345+
terminated by `,` and delimited by `(` and `)`. Each parameter in that list may
346+
optionally be prefixed by `OuterAttr+`.
347+
342348
### Variadics
343349

344350
Attributes may also be attached to `...` on variadic functions, e.g.
@@ -349,6 +355,8 @@ extern "C" {
349355
}
350356
```
351357

358+
That is, for the purposes of this RFC, `...` is considered as a parameter.
359+
352360
### Anonymous parameters in Rust 2015
353361

354362
In Rust 2015 edition, as `fn`s may have anonymous parameters, e.g.

0 commit comments

Comments
 (0)