Skip to content

Commit 56596ed

Browse files
huonwManishearth
authored andcommitted
Change & pat to only work with &T, and &mut with &mut T.
This implements RFC 179 by making the pattern `&<pat>` require matching against a variable of type `&T`, and introducing the pattern `&mut <pat>` which only works with variables of type `&mut T`. The pattern `&mut x` currently parses as `&(mut x)` i.e. a pattern match through a `&T` or a `&mut T` that binds the variable `x` to have type `T` and to be mutable. This should be rewritten as follows, for example, for &mut x in slice.iter() { becomes for &x in slice.iter() { let mut x = x; Due to this, this is a [breaking-change] Closes rust-lang#20496.
1 parent a6ca77f commit 56596ed

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,8 +3484,9 @@ fn main() {
34843484
34853485
```
34863486

3487-
Patterns can also dereference pointers by using the `&`, `box` symbols,
3488-
as appropriate. For example, these two matches on `x: &int` are equivalent:
3487+
Patterns can also dereference pointers by using the `&`, `&mut` and `box`
3488+
symbols, as appropriate. For example, these two matches on `x: &int` are
3489+
equivalent:
34893490

34903491
```
34913492
# let x = &3i;

0 commit comments

Comments
 (0)