diff options
| author | bors <bors@rust-lang.org> | 2022-05-06 12:32:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-06 12:32:44 +0000 |
| commit | 9a251644fa2adde5f46eea8d342b7e60e4716039 (patch) | |
| tree | 7017ac2f53456a2a7df4338f7a5186ead387f3e0 /src | |
| parent | 8c4fc9d9a45b0577f583abda870386f1f940c706 (diff) | |
| parent | 2300401fb0a44966a2159dd0a69762b18fd89345 (diff) | |
Auto merge of #96268 - jackh726:remove-mutable_borrow_reservation_conflict-lint, r=nikomatsakis
Remove mutable_borrow_reservation_conflict lint and allow the code pattern This was the only breaking issue with the NLL stabilization PR. Lang team decided to go ahead and allow this. r? `@nikomatsakis` Closes #59159 Closes #56254
Diffstat (limited to 'src')
17 files changed, 76 insertions, 276 deletions
diff --git a/src/test/ui/borrowck/suggest-local-var-imm-and-mut.nll.stderr b/src/test/ui/borrowck/suggest-local-var-imm-and-mut.nll.stderr index 2ba0b6b28aa..eb934e7b72b 100644 --- a/src/test/ui/borrowck/suggest-local-var-imm-and-mut.nll.stderr +++ b/src/test/ui/borrowck/suggest-local-var-imm-and-mut.nll.stderr @@ -7,23 +7,12 @@ LL | self.foo(self.bar()); | | | mutable borrow occurs here | | immutable borrow later used by call | immutable borrow occurs here - | -help: try adding a local storing this argument... - --> $DIR/suggest-local-var-imm-and-mut.rs:12:22 - | -LL | self.foo(self.bar()); - | ^^^^^^^^^^ -help: ...and then using that local as the argument to this call - --> $DIR/suggest-local-var-imm-and-mut.rs:12:13 - | -LL | self.foo(self.bar()); - | ^^^^^^^^^^^^^^^^^^^^ error[E0502]: cannot borrow `*self` as mutable because it is also borrowed as immutable - --> $DIR/suggest-local-var-imm-and-mut.rs:24:39 + --> $DIR/suggest-local-var-imm-and-mut.rs:24:29 | LL | Self::foo(self, Self::bar(self)); - | --------- ---- ^^^^ mutable borrow occurs here + | --------- ---- ^^^^^^^^^^^^^^^ mutable borrow occurs here | | | | | immutable borrow occurs here | immutable borrow later used by call diff --git a/src/test/ui/borrowck/two-phase-cannot-nest-mut-self-calls.stderr b/src/test/ui/borrowck/two-phase-cannot-nest-mut-self-calls.stderr index 85c7159952f..a89bb941532 100644 --- a/src/test/ui/borrowck/two-phase-cannot-nest-mut-self-calls.stderr +++ b/src/test/ui/borrowck/two-phase-cannot-nest-mut-self-calls.stderr @@ -13,23 +13,6 @@ LL | | LL | | 0 LL | | }); | |______- immutable borrow occurs here - | -help: try adding a local storing this argument... - --> $DIR/two-phase-cannot-nest-mut-self-calls.rs:16:9 - | -LL | vec.push(2); - | ^^^^^^^^^^^ -help: ...and then using that local as the argument to this call - --> $DIR/two-phase-cannot-nest-mut-self-calls.rs:14:5 - | -LL | / vec.get({ -LL | | -LL | | vec.push(2); -LL | | -LL | | -LL | | 0 -LL | | }); - | |______^ error: aborting due to previous error diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.base.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.base.stderr new file mode 100644 index 00000000000..cbbbde61917 --- /dev/null +++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.base.stderr @@ -0,0 +1,25 @@ +error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable + --> $DIR/two-phase-reservation-sharing-interference-2.rs:19:5 + | +LL | let shared = &v; + | -- immutable borrow occurs here +LL | +LL | v.extend(shared); + | ^^------^^^^^^^^ + | | | + | | immutable borrow later used by call + | mutable borrow occurs here + +error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable + --> $DIR/two-phase-reservation-sharing-interference-2.rs:27:5 + | +LL | v.extend(&v); + | ^^------^--^ + | | | | + | | | immutable borrow occurs here + | | immutable borrow later used by call + | mutable borrow occurs here + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2015.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2015.stderr index 6cff53399ca..69c3d7915e4 100644 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2015.stderr +++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2015.stderr @@ -20,22 +20,6 @@ LL | v.extend(&v); | | immutable borrow later used by call | mutable borrow occurs here -warning: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-2.rs:40:5 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - | - = note: `#[warn(mutable_borrow_reservation_conflict)]` on by default - = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future - = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159> - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2018.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2018.stderr index 6cff53399ca..69c3d7915e4 100644 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2018.stderr +++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2018.stderr @@ -20,22 +20,6 @@ LL | v.extend(&v); | | immutable borrow later used by call | mutable borrow occurs here -warning: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-2.rs:40:5 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - | - = note: `#[warn(mutable_borrow_reservation_conflict)]` on by default - = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future - = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159> - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll.stderr new file mode 100644 index 00000000000..cbbbde61917 --- /dev/null +++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll.stderr @@ -0,0 +1,25 @@ +error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable + --> $DIR/two-phase-reservation-sharing-interference-2.rs:19:5 + | +LL | let shared = &v; + | -- immutable borrow occurs here +LL | +LL | v.extend(shared); + | ^^------^^^^^^^^ + | | | + | | immutable borrow later used by call + | mutable borrow occurs here + +error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable + --> $DIR/two-phase-reservation-sharing-interference-2.rs:27:5 + | +LL | v.extend(&v); + | ^^------^--^ + | | | | + | | | immutable borrow occurs here + | | immutable borrow later used by call + | mutable borrow occurs here + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2015.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2015.stderr index 0ae6fe78c6a..69c3d7915e4 100644 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2015.stderr +++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2015.stderr @@ -5,9 +5,9 @@ LL | let shared = &v; | -- immutable borrow occurs here LL | LL | v.extend(shared); - | ^^^^^^^^^------^ - | | | - | | immutable borrow later used here + | ^^------^^^^^^^^ + | | | + | | immutable borrow later used by call | mutable borrow occurs here error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable @@ -20,18 +20,6 @@ LL | v.extend(&v); | | immutable borrow later used by call | mutable borrow occurs here -error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-2.rs:40:5 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2018.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2018.stderr index 0ae6fe78c6a..69c3d7915e4 100644 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2018.stderr +++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2018.stderr @@ -5,9 +5,9 @@ LL | let shared = &v; | -- immutable borrow occurs here LL | LL | v.extend(shared); - | ^^^^^^^^^------^ - | | | - | | immutable borrow later used here + | ^^------^^^^^^^^ + | | | + | | immutable borrow later used by call | mutable borrow occurs here error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable @@ -20,18 +20,6 @@ LL | v.extend(&v); | | immutable borrow later used by call | mutable borrow occurs here -error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-2.rs:40:5 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.rs b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.rs index 14f687c2378..3e125869ef1 100644 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.rs +++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.rs @@ -1,50 +1,39 @@ -// Test for #56254, we previously allowed the last example on the 2018 -// edition. Make sure that we now emit a warning in that case and an error for -// everyone else. +// Test for #56254. The last example originally failed with the ast checker, was +// accidentally allowed under migrate/nll, then linted against in migrate mode +// but disallowed under NLL. Now, we accept it everywhere. //ignore-compare-mode-nll //ignore-compare-mode-polonius -//revisions: migrate2015 migrate2018 nll2015 nll2018 +//revisions: base nll //[migrate2018] edition:2018 //[nll2018] edition:2018 -#![cfg_attr(any(nll2015, nll2018), feature(nll))] +#![cfg_attr(nll, feature(nll))] fn double_conflicts() { let mut v = vec![0, 1, 2]; let shared = &v; v.extend(shared); - //[migrate2015]~^ ERROR cannot borrow `v` as mutable - //[nll2015]~^^ ERROR cannot borrow `v` as mutable - //[migrate2018]~^^^ ERROR cannot borrow `v` as mutable - //[nll2018]~^^^^ ERROR cannot borrow `v` as mutable + //[base]~^ ERROR cannot borrow `v` as mutable + //[nll]~^^ ERROR cannot borrow `v` as mutable } fn activation_conflict() { let mut v = vec![0, 1, 2]; v.extend(&v); - //[migrate2015]~^ ERROR cannot borrow `v` as mutable - //[nll2015]~^^ ERROR cannot borrow `v` as mutable - //[migrate2018]~^^^ ERROR cannot borrow `v` as mutable - //[nll2018]~^^^^ ERROR cannot borrow `v` as mutable + //[base]~^ ERROR cannot borrow `v` as mutable + //[nll]~^^ ERROR cannot borrow `v` as mutable } -fn reservation_conflict() { +fn reservation_allowed() { let mut v = vec![0, 1, 2]; let shared = &v; v.push(shared.len()); - //[nll2015]~^ ERROR cannot borrow `v` as mutable - //[nll2018]~^^ ERROR cannot borrow `v` as mutable - //[migrate2015]~^^^ WARNING cannot borrow `v` as mutable - //[migrate2015]~| WARNING may become a hard error in the future - - //[migrate2018]~^^^^^^ WARNING cannot borrow `v` as mutable - //[migrate2018]~| WARNING may become a hard error in the future } fn main() {} diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.nll.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.nll.stderr deleted file mode 100644 index 52e8de3c4ac..00000000000 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.nll.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:13:9 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - -error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:24:9 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - -error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:37:9 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs deleted file mode 100644 index 0e1d77ace3f..00000000000 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Check that the future-compat-lint for the reservation conflict is -// handled like any other lint. - -// edition:2018 - -mod future_compat_allow { - #![allow(mutable_borrow_reservation_conflict)] - - fn reservation_conflict() { - let mut v = vec![0, 1, 2]; - let shared = &v; - - v.push(shared.len()); - } -} - -mod future_compat_warn { - #![warn(mutable_borrow_reservation_conflict)] - - fn reservation_conflict() { - let mut v = vec![0, 1, 2]; - let shared = &v; - - v.push(shared.len()); - //~^ WARNING cannot borrow `v` as mutable - //~| WARNING may become a hard error in the future - } -} - -mod future_compat_deny { - #![deny(mutable_borrow_reservation_conflict)] - - fn reservation_conflict() { - let mut v = vec![0, 1, 2]; - let shared = &v; - - v.push(shared.len()); - //~^ ERROR cannot borrow `v` as mutable - //~| WARNING may become a hard error in the future - } -} - -fn main() {} diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr deleted file mode 100644 index aab21c9e78b..00000000000 --- a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr +++ /dev/null @@ -1,42 +0,0 @@ -warning: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:24:9 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - | -note: the lint level is defined here - --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:18:13 - | -LL | #![warn(mutable_borrow_reservation_conflict)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future - = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159> - -error: cannot borrow `v` as mutable because it is also borrowed as immutable - --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:37:9 - | -LL | let shared = &v; - | -- immutable borrow occurs here -LL | -LL | v.push(shared.len()); - | ^^^^^^^------------^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - | -note: the lint level is defined here - --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:31:13 - | -LL | #![deny(mutable_borrow_reservation_conflict)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future - = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159> - -error: aborting due to previous error; 1 warning emitted - diff --git a/src/test/ui/error-codes/E0502.nll.stderr b/src/test/ui/error-codes/E0502.nll.stderr index a3c7ef76189..94cc89754db 100644 --- a/src/test/ui/error-codes/E0502.nll.stderr +++ b/src/test/ui/error-codes/E0502.nll.stderr @@ -1,10 +1,10 @@ error[E0502]: cannot borrow `*a` as mutable because it is also borrowed as immutable - --> $DIR/E0502.rs:4:9 + --> $DIR/E0502.rs:4:5 | LL | let ref y = a; | ----- immutable borrow occurs here LL | bar(a); - | ^ mutable borrow occurs here + | ^^^^^^ mutable borrow occurs here LL | y.use_ref(); | ----------- immutable borrow later used here diff --git a/src/test/ui/issues/issue-61623.rs b/src/test/ui/issues/issue-61623.rs index e5b8747bd80..82df50d9dc3 100644 --- a/src/test/ui/issues/issue-61623.rs +++ b/src/test/ui/issues/issue-61623.rs @@ -5,7 +5,6 @@ fn f2<P>(_: P, _: ()) {} fn f3<'a>(x: &'a ((), &'a mut ())) { f2(|| x.0, f1(x.1)) //~^ ERROR cannot borrow `*x.1` as mutable, as it is behind a `&` reference -//~| ERROR cannot borrow `*x.1` as mutable because it is also borrowed as immutable } fn main() {} diff --git a/src/test/ui/issues/issue-61623.stderr b/src/test/ui/issues/issue-61623.stderr index 901c7598176..f6546054233 100644 --- a/src/test/ui/issues/issue-61623.stderr +++ b/src/test/ui/issues/issue-61623.stderr @@ -6,17 +6,6 @@ LL | fn f3<'a>(x: &'a ((), &'a mut ())) { LL | f2(|| x.0, f1(x.1)) | ^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable -error[E0502]: cannot borrow `*x.1` as mutable because it is also borrowed as immutable - --> $DIR/issue-61623.rs:6:19 - | -LL | f2(|| x.0, f1(x.1)) - | -- -- --- ^^^ mutable borrow occurs here - | | | | - | | | first borrow occurs due to use of `x` in closure - | | immutable borrow occurs here - | immutable borrow later used by call - -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0502, E0596. -For more information about an error, try `rustc --explain E0502`. +For more information about this error, try `rustc --explain E0596`. diff --git a/src/test/ui/nll/lint-no-err.rs b/src/test/ui/nll/lint-no-err.rs index 4b4169faadf..f5f7bf0a758 100644 --- a/src/test/ui/nll/lint-no-err.rs +++ b/src/test/ui/nll/lint-no-err.rs @@ -23,6 +23,4 @@ fn main() { let mut conflict = Repro; let prev = conflict.get(); conflict.insert(*prev + *x); - //~^ WARN cannot borrow `conflict` as mutable because it is also borrowed as immutable - //~| WARN this borrowing pattern was not meant to be accepted } diff --git a/src/test/ui/nll/lint-no-err.stderr b/src/test/ui/nll/lint-no-err.stderr deleted file mode 100644 index 1e7aecfaa64..00000000000 --- a/src/test/ui/nll/lint-no-err.stderr +++ /dev/null @@ -1,17 +0,0 @@ -warning: cannot borrow `conflict` as mutable because it is also borrowed as immutable - --> $DIR/lint-no-err.rs:25:5 - | -LL | let prev = conflict.get(); - | -------------- immutable borrow occurs here -LL | conflict.insert(*prev + *x); - | ^^^^^^^^^^^^^^^^-----^^^^^^ - | | | - | | immutable borrow later used here - | mutable borrow occurs here - | - = note: `#[warn(mutable_borrow_reservation_conflict)]` on by default - = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future - = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159> - -warning: 1 warning emitted - |
