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 #20496.
This commit is contained in:
parent
5773bdefff
commit
bf6c007760
19 changed files with 91 additions and 25 deletions
|
@ -3357,11 +3357,16 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
token::BinOp(token::And) | token::AndAnd => {
|
||||
// parse &pat
|
||||
// parse &pat and &mut pat
|
||||
let lo = self.span.lo;
|
||||
self.expect_and();
|
||||
let mutability = if self.eat_keyword(keywords::Mut) {
|
||||
ast::MutMutable
|
||||
} else {
|
||||
ast::MutImmutable
|
||||
};
|
||||
let sub = self.parse_pat();
|
||||
pat = PatRegion(sub);
|
||||
pat = PatRegion(sub, mutability);
|
||||
hi = self.last_span.hi;
|
||||
return P(ast::Pat {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue