]> git.lizzy.rs Git - rust.git/commit
Change `&` pat to only work with &T, and `&mut` with &mut T.
authorHuon Wilson <dbau.pp+github@gmail.com>
Fri, 5 Dec 2014 23:56:25 +0000 (15:56 -0800)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 5 Jan 2015 05:14:17 +0000 (16:14 +1100)
commitbf6c007760169e9c382d3700fd1cdd20037e4343
tree248a48e3811afdf8908c5ebf260d67eade27aa92
parent5773bdefff2e47cc007f5cc2af3f80b30303d45a
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.
19 files changed:
src/doc/reference.md
src/libcore/str/mod.rs
src/librustc/middle/cfg/construct.rs
src/librustc/middle/check_match.rs
src/librustc/middle/mem_categorization.rs
src/librustc_trans/trans/_match.rs
src/librustc_trans/trans/debuginfo.rs
src/librustc_typeck/check/_match.rs
src/librustdoc/clean/mod.rs
src/libsyntax/ast.rs
src/libsyntax/ast_util.rs
src/libsyntax/ext/deriving/generic/mod.rs
src/libsyntax/fold.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/libsyntax/visit.rs
src/libtest/stats.rs
src/test/compile-fail/mut-pattern-internal-mutability.rs [new file with mode: 0644]
src/test/compile-fail/mut-pattern-mismatched.rs [new file with mode: 0644]