]> git.lizzy.rs Git - rust.git/blob - src/test/ui/reassign-ref-mut.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[rust.git] / src / test / ui / reassign-ref-mut.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Tests how we behave when the user attempts to mutate an immutable
12 // binding that was introduced by either `ref` or `ref mut`
13 // patterns.
14 //
15 // Such bindings cannot be made mutable via the mere addition of the
16 // `mut` keyword, and thus we want to check that the compiler does not
17 // suggest doing so.
18
19 fn main() {
20     let (mut one_two, mut three_four) = ((1, 2), (3, 4));
21     let &mut (ref a, ref mut b) = &mut one_two;
22     a = &three_four.0;
23     //~^ ERROR cannot assign twice to immutable variable `a` [E0384]
24     b = &mut three_four.1;
25     //~^ ERROR cannot assign twice to immutable variable `b` [E0384]
26 }