File: mut-patterns.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (52 lines) | stat: -rw-r--r-- 1,748 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Can't put mut in non-ident pattern

//@ edition:2018

#![feature(box_patterns)]
#![allow(warnings)]

pub fn main() {
    let mut _ = 0; //~ ERROR `mut` must be followed by a named binding
    let mut (_, _) = (0, 0); //~ ERROR `mut` must be followed by a named binding

    let mut (x @ y) = 0; //~ ERROR `mut` must be attached to each individual binding

    let mut mut x = 0;
    //~^ ERROR `mut` on a binding may not be repeated
    //~| remove the additional `mut`s

    let mut mut mut mut mut x = 0;
    //~^ ERROR `mut` on a binding may not be repeated
    //~| remove the additional `mut`s

    struct Foo { x: isize }
    let mut Foo { x: x } = Foo { x: 3 };
    //~^ ERROR `mut` must be attached to each individual binding
    //~| add `mut` to each binding

    let mut Foo { x } = Foo { x: 3 };
    //~^ ERROR `mut` must be attached to each individual binding
    //~| add `mut` to each binding

    struct r#yield(u8, u8);
    let mut mut yield(become, await) = r#yield(0, 0);
    //~^ ERROR `mut` on a binding may not be repeated
    //~| ERROR `mut` must be followed by a named binding
    //~| ERROR expected identifier, found reserved keyword `yield`
    //~| ERROR expected identifier, found reserved keyword `become`
    //~| ERROR expected identifier, found keyword `await`

    struct W<T, U>(T, U);
    struct B { f: Box<u8> }
    let mut W(mut a, W(b, W(ref c, W(d, B { box f }))))
    //~^ ERROR `mut` must be attached to each individual binding
        = W(0, W(1, W(2, W(3, B { f: Box::new(4u8) }))));

    // Make sure we don't accidentally allow `mut $p` where `$p:pat`.
    macro_rules! foo {
        ($p:pat) => {
            let mut $p = 0; //~ ERROR expected identifier, found `x`
        }
    }
    foo!(x);
}