]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/mut-patterns.rs
Merge commit 'c19edfd71a1d0ddef86c2c67fdb40718d40a72b4' into sync_cg_clif-2022-07-25
[rust.git] / src / test / ui / parser / mut-patterns.rs
1 // Can't put mut in non-ident pattern
2
3 // edition:2018
4
5 #![feature(box_patterns)]
6 #![allow(warnings)]
7
8 pub fn main() {
9     let mut _ = 0; //~ ERROR `mut` must be followed by a named binding
10     let mut (_, _) = (0, 0); //~ ERROR `mut` must be followed by a named binding
11
12     let mut (x @ y) = 0; //~ ERROR `mut` must be attached to each individual binding
13
14     let mut mut x = 0;
15     //~^ ERROR `mut` on a binding may not be repeated
16     //~| remove the additional `mut`s
17
18     struct Foo { x: isize }
19     let mut Foo { x: x } = Foo { x: 3 };
20     //~^ ERROR `mut` must be attached to each individual binding
21     //~| add `mut` to each binding
22
23     let mut Foo { x } = Foo { x: 3 };
24     //~^ ERROR `mut` must be attached to each individual binding
25     //~| add `mut` to each binding
26
27     struct r#yield(u8, u8);
28     let mut mut yield(become, await) = r#yield(0, 0);
29     //~^ ERROR `mut` on a binding may not be repeated
30     //~| ERROR `mut` must be attached to each individual binding
31     //~| ERROR expected identifier, found reserved keyword `yield`
32     //~| ERROR expected identifier, found reserved keyword `become`
33     //~| ERROR expected identifier, found keyword `await`
34
35     struct W<T, U>(T, U);
36     struct B { f: Box<u8> }
37     let mut W(mut a, W(b, W(ref c, W(d, B { box f }))))
38     //~^ ERROR `mut` must be attached to each individual binding
39         = W(0, W(1, W(2, W(3, B { f: Box::new(4u8) }))));
40
41     // Make sure we don't accidentally allow `mut $p` where `$p:pat`.
42     macro_rules! foo {
43         ($p:pat) => {
44             let mut $p = 0; //~ ERROR expected identifier, found `x`
45         }
46     }
47     foo!(x);
48 }