about summary refs log tree commit diff
path: root/tests/ui/suggestions/suggest-split-at-mut.rs
blob: 61704abbd36498ecad0b0f5f6dccaedd535711de (plain)
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
53
54
55
56
57
58
59
60
61
62
fn foo() {
    let mut foo = [1, 2, 3, 4];
    let a = &mut foo[2];
    let b = &mut foo[3]; //~ ERROR cannot borrow `foo[_]` as mutable more than once at a time
    *a = 5;
    *b = 6;
    println!("{:?} {:?}", a, b);
}

fn bar() {
    let mut foo = [1,2,3,4];
    let a = &mut foo[..2];
    let b = &mut foo[2..]; //~ ERROR cannot borrow `foo` as mutable more than once at a time
    a[0] = 5;
    b[0] = 6;
    println!("{:?} {:?}", a, b);
}

fn baz() {
    let mut foo = [1,2,3,4];
    let a = &foo[..2];
    let b = &mut foo[2..]; //~ ERROR cannot borrow `foo` as mutable because it is also borrowed as immutable
    b[0] = 6;
    println!("{:?} {:?}", a, b);
}

fn qux() {
    let mut foo = [1,2,3,4];
    let a = &mut foo[..2];
    let b = &foo[2..]; //~ ERROR cannot borrow `foo` as immutable because it is also borrowed as mutable
    a[0] = 5;
    println!("{:?} {:?}", a, b);
}

fn bad() {
    let mut foo = [1,2,3,4];
    let a = &foo[1];
    let b = &mut foo[2]; //~ ERROR cannot borrow `foo[_]` as mutable because it is also borrowed as immutable
    *b = 6;
    println!("{:?} {:?}", a, b);
}

fn bat() {
    let mut foo = [1,2,3,4];
    let a = &mut foo[1];
    let b = &foo[2]; //~ ERROR cannot borrow `foo[_]` as immutable because it is also borrowed as mutable
    *a = 5;
    println!("{:?} {:?}", a, b);
}

fn ang() {
    let mut foo = [1,2,3,4];
    let a = &mut foo[0..];
    let b = &foo[0..]; //~ ERROR cannot borrow `foo` as immutable because it is also borrowed as mutable
    a[0] = 5;
    println!("{:?} {:?}", a, b);
}

fn main() {
    foo();
    bar();
}