]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/issue-85765.rs
Do not use a suggestion to change a binding's name to a type
[rust.git] / src / test / ui / borrowck / issue-85765.rs
1 fn main() {
2     let mut test = Vec::new();
3     let rofl: &Vec<Vec<i32>> = &mut test;
4     //~^ NOTE consider changing this binding's type to be
5     rofl.push(Vec::new());
6     //~^ ERROR cannot borrow `*rofl` as mutable, as it is behind a `&` reference
7     //~| NOTE `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable
8
9     let mut mutvar = 42;
10     let r = &mutvar;
11     //~^ HELP consider changing this to be a mutable reference
12     *r = 0;
13     //~^ ERROR cannot assign to `*r`, which is behind a `&` reference
14     //~| NOTE `r` is a `&` reference, so the data it refers to cannot be written
15
16     #[rustfmt::skip]
17     let x: &usize = &mut{0};
18     //~^ NOTE consider changing this binding's type to be
19     *x = 1;
20     //~^ ERROR cannot assign to `*x`, which is behind a `&` reference
21     //~| NOTE `x` is a `&` reference, so the data it refers to cannot be written
22
23     #[rustfmt::skip]
24     let y: &usize = &mut(0);
25     //~^ NOTE consider changing this binding's type to be
26     *y = 1;
27     //~^ ERROR cannot assign to `*y`, which is behind a `&` reference
28     //~| NOTE `y` is a `&` reference, so the data it refers to cannot be written
29 }