-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Remove mutable_borrow_reservation_conflict lint and allow the code pattern #96268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2345,40 +2345,6 @@ declare_lint! { | |
}; | ||
} | ||
|
||
declare_lint! { | ||
/// The `mutable_borrow_reservation_conflict` lint detects the reservation | ||
/// of a two-phased borrow that conflicts with other shared borrows. | ||
/// | ||
/// ### Example | ||
/// | ||
/// ```rust | ||
/// let mut v = vec![0, 1, 2]; | ||
/// let shared = &v; | ||
/// v.push(shared.len()); | ||
/// ``` | ||
/// | ||
/// {{produces}} | ||
/// | ||
/// ### Explanation | ||
/// | ||
/// This is a [future-incompatible] lint to transition this to a hard error | ||
/// in the future. See [issue #59159] for a complete description of the | ||
/// problem, and some possible solutions. | ||
/// | ||
/// [issue #59159]: https://github.com/rust-lang/rust/issues/59159 | ||
/// [future-incompatible]: ../index.md#future-incompatible-lints | ||
pub MUTABLE_BORROW_RESERVATION_CONFLICT, | ||
Warn, | ||
"reservation of a two-phased borrow conflicts with other shared borrows", | ||
@future_incompatible = FutureIncompatibleInfo { | ||
reason: FutureIncompatibilityReason::Custom( | ||
"this borrowing pattern was not meant to be accepted, \ | ||
and may become a hard error in the future" | ||
), | ||
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>", | ||
}; | ||
} | ||
|
||
declare_lint! { | ||
/// The `soft_unstable` lint detects unstable features that were | ||
/// unintentionally allowed on stable. | ||
|
@@ -3179,7 +3145,6 @@ declare_lint_pass! { | |
META_VARIABLE_MISUSE, | ||
DEPRECATED_IN_FUTURE, | ||
AMBIGUOUS_ASSOCIATED_ITEMS, | ||
MUTABLE_BORROW_RESERVATION_CONFLICT, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't normally remove these altogether but rather move them to some list of deprecated lints ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets registered as removed here: https://github.com/rust-lang/rust/pull/96268/files#diff-cfb1d20a5949dd50b9769edb62eaf10a0de66734637fe71d35bdcf8fb06d767bR494 |
||
INDIRECT_STRUCTURAL_MATCH, | ||
POINTER_STRUCTURAL_MATCH, | ||
NONTRIVIAL_STRUCTURAL_MATCH, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.