Skip to content

Commit

Permalink
rfc/param-attrs: clarify grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 17, 2019
1 parent 009286d commit d4ff544
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions text/2540-formal-function-parameter-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ fn foo(#[inline] bar: u32) { .. }
Let `OuterAttr` denote the production for an attribute `#[...]`.

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

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

fn g8(#[attr] self: Self) { .. }

fn g9(#[attr] self: Rc<Self>) { .. }
```

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

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

### Variadics

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

That is, for the purposes of this RFC, `...` is considered as a parameter.

### Anonymous parameters in Rust 2015

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

0 comments on commit d4ff544

Please sign in to comment.