]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.rs
Rollup merge of #88090 - nbdd0121:inference, r=nikomatsakis
[rust.git] / src / test / ui / borrowck / two-phase-reservation-sharing-interference-2.rs
1 // Test for #56254, we previously allowed the last example on the 2018
2 // edition. Make sure that we now emit a warning in that case and an error for
3 // everyone else.
4
5 //ignore-compare-mode-nll
6 //ignore-compare-mode-polonius
7
8 //revisions: migrate2015 migrate2018 nll2015 nll2018
9
10 //[migrate2018] edition:2018
11 //[nll2018] edition:2018
12
13 #![cfg_attr(any(nll2015, nll2018), feature(nll))]
14
15 fn double_conflicts() {
16     let mut v = vec![0, 1, 2];
17     let shared = &v;
18
19     v.extend(shared);
20     //[migrate2015]~^ ERROR cannot borrow `v` as mutable
21     //[nll2015]~^^ ERROR cannot borrow `v` as mutable
22     //[migrate2018]~^^^ ERROR cannot borrow `v` as mutable
23     //[nll2018]~^^^^ ERROR cannot borrow `v` as mutable
24 }
25
26 fn activation_conflict() {
27     let mut v = vec![0, 1, 2];
28
29     v.extend(&v);
30     //[migrate2015]~^ ERROR cannot borrow `v` as mutable
31     //[nll2015]~^^ ERROR cannot borrow `v` as mutable
32     //[migrate2018]~^^^ ERROR cannot borrow `v` as mutable
33     //[nll2018]~^^^^ ERROR cannot borrow `v` as mutable
34 }
35
36 fn reservation_conflict() {
37     let mut v = vec![0, 1, 2];
38     let shared = &v;
39
40     v.push(shared.len());
41     //[nll2015]~^ ERROR cannot borrow `v` as mutable
42     //[nll2018]~^^ ERROR cannot borrow `v` as mutable
43     //[migrate2015]~^^^ WARNING cannot borrow `v` as mutable
44     //[migrate2015]~| WARNING may become a hard error in the future
45
46     //[migrate2018]~^^^^^^ WARNING cannot borrow `v` as mutable
47     //[migrate2018]~| WARNING may become a hard error in the future
48 }
49
50 fn main() {}