Skip to content

Commit 2300401

Browse files
committed
Remove mutable_borrow_reservation_conflict lint
1 parent febce1f commit 2300401

21 files changed

+89
-380
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

-4
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ impl<'tcx> BorrowSet<'tcx> {
167167
crate fn get_index_of(&self, location: &Location) -> Option<BorrowIndex> {
168168
self.location_map.get_index_of(location).map(BorrowIndex::from)
169169
}
170-
171-
crate fn contains(&self, location: &Location) -> bool {
172-
self.location_map.contains_key(location)
173-
}
174170
}
175171

176172
struct GatherBorrows<'a, 'tcx> {

compiler/rustc_borrowck/src/lib.rs

+8-65
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ use rustc_middle::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, Stat
3535
use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind};
3636
use rustc_middle::ty::query::Providers;
3737
use rustc_middle::ty::{self, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
38-
use rustc_session::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT, UNUSED_MUT};
39-
use rustc_span::{Span, Symbol, DUMMY_SP};
38+
use rustc_session::lint::builtin::UNUSED_MUT;
39+
use rustc_span::{Span, Symbol};
4040

4141
use either::Either;
4242
use smallvec::SmallVec;
4343
use std::cell::RefCell;
4444
use std::collections::BTreeMap;
45-
use std::mem;
4645
use std::rc::Rc;
4746

4847
use rustc_mir_dataflow::impls::{
@@ -313,7 +312,6 @@ fn do_mir_borrowck<'a, 'tcx>(
313312
locals_are_invalidated_at_exit,
314313
access_place_error_reported: Default::default(),
315314
reservation_error_reported: Default::default(),
316-
reservation_warnings: Default::default(),
317315
uninitialized_error_reported: Default::default(),
318316
regioncx: regioncx.clone(),
319317
used_mut: Default::default(),
@@ -345,7 +343,6 @@ fn do_mir_borrowck<'a, 'tcx>(
345343
fn_self_span_reported: Default::default(),
346344
access_place_error_reported: Default::default(),
347345
reservation_error_reported: Default::default(),
348-
reservation_warnings: Default::default(),
349346
uninitialized_error_reported: Default::default(),
350347
regioncx: Rc::clone(&regioncx),
351348
used_mut: Default::default(),
@@ -378,34 +375,6 @@ fn do_mir_borrowck<'a, 'tcx>(
378375
&mut mbcx,
379376
);
380377

381-
// Convert any reservation warnings into lints.
382-
let reservation_warnings = mem::take(&mut mbcx.reservation_warnings);
383-
for (_, (place, span, location, bk, borrow)) in reservation_warnings {
384-
let initial_diag = mbcx.report_conflicting_borrow(location, (place, span), bk, &borrow);
385-
386-
let scope = mbcx.body.source_info(location).scope;
387-
let lint_root = match &mbcx.body.source_scopes[scope].local_data {
388-
ClearCrossCrate::Set(data) => data.lint_root,
389-
_ => tcx.hir().local_def_id_to_hir_id(def.did),
390-
};
391-
392-
// Span and message don't matter; we overwrite them below anyway
393-
mbcx.infcx.tcx.struct_span_lint_hir(
394-
MUTABLE_BORROW_RESERVATION_CONFLICT,
395-
lint_root,
396-
DUMMY_SP,
397-
|lint| {
398-
let mut diag = lint.build("");
399-
400-
diag.message = initial_diag.styled_message().clone();
401-
diag.span = initial_diag.span.clone();
402-
403-
mbcx.buffer_non_error_diag(diag);
404-
},
405-
);
406-
initial_diag.cancel();
407-
}
408-
409378
// For each non-user used mutable variable, check if it's been assigned from
410379
// a user-declared local. If so, then put that local into the used_mut set.
411380
// Note that this set is expected to be small - only upvars from closures
@@ -540,11 +509,6 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
540509
/// used to report extra information for `FnSelfUse`, to avoid
541510
/// unnecessarily verbose errors.
542511
fn_self_span_reported: FxHashSet<Span>,
543-
/// Migration warnings to be reported for #56254. We delay reporting these
544-
/// so that we can suppress the warning if there's a corresponding error
545-
/// for the activation of the borrow.
546-
reservation_warnings:
547-
FxHashMap<BorrowIndex, (Place<'tcx>, Span, Location, BorrowKind, BorrowData<'tcx>)>,
548512
/// This field keeps track of errors reported in the checking of uninitialized variables,
549513
/// so that we don't report seemingly duplicate errors.
550514
uninitialized_error_reported: FxHashSet<PlaceRef<'tcx>>,
@@ -996,12 +960,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
996960
let conflict_error =
997961
self.check_access_for_conflict(location, place_span, sd, rw, flow_state);
998962

999-
if let (Activation(_, borrow_idx), true) = (kind.1, conflict_error) {
1000-
// Suppress this warning when there's an error being emitted for the
1001-
// same borrow: fixing the error is likely to fix the warning.
1002-
self.reservation_warnings.remove(&borrow_idx);
1003-
}
1004-
1005963
if conflict_error || mutability_error {
1006964
debug!("access_place: logging error place_span=`{:?}` kind=`{:?}`", place_span, kind);
1007965
self.access_place_error_reported.insert((place_span.0, place_span.1));
@@ -1068,6 +1026,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10681026
BorrowKind::Unique | BorrowKind::Mut { .. },
10691027
) => Control::Continue,
10701028

1029+
(Reservation(_), BorrowKind::Shallow | BorrowKind::Shared) => {
1030+
// This used to be a future compatibility warning (to be
1031+
// disallowed on NLL). See rust-lang/rust#56254
1032+
Control::Continue
1033+
}
1034+
10711035
(Write(WriteKind::Move), BorrowKind::Shallow) => {
10721036
// Handled by initialization checks.
10731037
Control::Continue
@@ -1096,27 +1060,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10961060
Control::Break
10971061
}
10981062

1099-
(
1100-
Reservation(WriteKind::MutableBorrow(bk)),
1101-
BorrowKind::Shallow | BorrowKind::Shared,
1102-
) if { tcx.migrate_borrowck() && this.borrow_set.contains(&location) } => {
1103-
let bi = this.borrow_set.get_index_of(&location).unwrap();
1104-
debug!(
1105-
"recording invalid reservation of place: {:?} with \
1106-
borrow index {:?} as warning",
1107-
place_span.0, bi,
1108-
);
1109-
// rust-lang/rust#56254 - This was previously permitted on
1110-
// the 2018 edition so we emit it as a warning. We buffer
1111-
// these separately so that we only emit a warning if borrow
1112-
// checking was otherwise successful.
1113-
this.reservation_warnings
1114-
.insert(bi, (place_span.0, place_span.1, location, bk, borrow.clone()));
1115-
1116-
// Don't suppress actual errors.
1117-
Control::Continue
1118-
}
1119-
11201063
(Reservation(kind) | Activation(kind, _) | Write(kind), _) => {
11211064
match rw {
11221065
Reservation(..) => {

compiler/rustc_lint/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
491491
"converted into hard error, see RFC 2972 \
492492
<https://github.com/rust-lang/rfcs/blob/master/text/2972-constrained-naked.md> for more information",
493493
);
494+
store.register_removed(
495+
"mutable_borrow_reservation_conflict",
496+
"now allowed, see issue #59159 \
497+
<https://github.com/rust-lang/rust/issues/59159> for more information",
498+
);
494499
}
495500

496501
fn register_internals(store: &mut LintStore) {

compiler/rustc_lint_defs/src/builtin.rs

-35
Original file line numberDiff line numberDiff line change
@@ -2345,40 +2345,6 @@ declare_lint! {
23452345
};
23462346
}
23472347

2348-
declare_lint! {
2349-
/// The `mutable_borrow_reservation_conflict` lint detects the reservation
2350-
/// of a two-phased borrow that conflicts with other shared borrows.
2351-
///
2352-
/// ### Example
2353-
///
2354-
/// ```rust
2355-
/// let mut v = vec![0, 1, 2];
2356-
/// let shared = &v;
2357-
/// v.push(shared.len());
2358-
/// ```
2359-
///
2360-
/// {{produces}}
2361-
///
2362-
/// ### Explanation
2363-
///
2364-
/// This is a [future-incompatible] lint to transition this to a hard error
2365-
/// in the future. See [issue #59159] for a complete description of the
2366-
/// problem, and some possible solutions.
2367-
///
2368-
/// [issue #59159]: https://github.com/rust-lang/rust/issues/59159
2369-
/// [future-incompatible]: ../index.md#future-incompatible-lints
2370-
pub MUTABLE_BORROW_RESERVATION_CONFLICT,
2371-
Warn,
2372-
"reservation of a two-phased borrow conflicts with other shared borrows",
2373-
@future_incompatible = FutureIncompatibleInfo {
2374-
reason: FutureIncompatibilityReason::Custom(
2375-
"this borrowing pattern was not meant to be accepted, \
2376-
and may become a hard error in the future"
2377-
),
2378-
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
2379-
};
2380-
}
2381-
23822348
declare_lint! {
23832349
/// The `soft_unstable` lint detects unstable features that were
23842350
/// unintentionally allowed on stable.
@@ -3179,7 +3145,6 @@ declare_lint_pass! {
31793145
META_VARIABLE_MISUSE,
31803146
DEPRECATED_IN_FUTURE,
31813147
AMBIGUOUS_ASSOCIATED_ITEMS,
3182-
MUTABLE_BORROW_RESERVATION_CONFLICT,
31833148
INDIRECT_STRUCTURAL_MATCH,
31843149
POINTER_STRUCTURAL_MATCH,
31853150
NONTRIVIAL_STRUCTURAL_MATCH,

src/test/ui/borrowck/suggest-local-var-imm-and-mut.nll.stderr

+2-13
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,12 @@ LL | self.foo(self.bar());
77
| | | mutable borrow occurs here
88
| | immutable borrow later used by call
99
| immutable borrow occurs here
10-
|
11-
help: try adding a local storing this argument...
12-
--> $DIR/suggest-local-var-imm-and-mut.rs:12:22
13-
|
14-
LL | self.foo(self.bar());
15-
| ^^^^^^^^^^
16-
help: ...and then using that local as the argument to this call
17-
--> $DIR/suggest-local-var-imm-and-mut.rs:12:13
18-
|
19-
LL | self.foo(self.bar());
20-
| ^^^^^^^^^^^^^^^^^^^^
2110

2211
error[E0502]: cannot borrow `*self` as mutable because it is also borrowed as immutable
23-
--> $DIR/suggest-local-var-imm-and-mut.rs:24:39
12+
--> $DIR/suggest-local-var-imm-and-mut.rs:24:29
2413
|
2514
LL | Self::foo(self, Self::bar(self));
26-
| --------- ---- ^^^^ mutable borrow occurs here
15+
| --------- ---- ^^^^^^^^^^^^^^^ mutable borrow occurs here
2716
| | |
2817
| | immutable borrow occurs here
2918
| immutable borrow later used by call

src/test/ui/borrowck/two-phase-cannot-nest-mut-self-calls.stderr

-17
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,6 @@ LL | |
1313
LL | | 0
1414
LL | | });
1515
| |______- immutable borrow occurs here
16-
|
17-
help: try adding a local storing this argument...
18-
--> $DIR/two-phase-cannot-nest-mut-self-calls.rs:16:9
19-
|
20-
LL | vec.push(2);
21-
| ^^^^^^^^^^^
22-
help: ...and then using that local as the argument to this call
23-
--> $DIR/two-phase-cannot-nest-mut-self-calls.rs:14:5
24-
|
25-
LL | / vec.get({
26-
LL | |
27-
LL | | vec.push(2);
28-
LL | |
29-
LL | |
30-
LL | | 0
31-
LL | | });
32-
| |______^
3316

3417
error: aborting due to previous error
3518

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
2+
--> $DIR/two-phase-reservation-sharing-interference-2.rs:19:5
3+
|
4+
LL | let shared = &v;
5+
| -- immutable borrow occurs here
6+
LL |
7+
LL | v.extend(shared);
8+
| ^^------^^^^^^^^
9+
| | |
10+
| | immutable borrow later used by call
11+
| mutable borrow occurs here
12+
13+
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
14+
--> $DIR/two-phase-reservation-sharing-interference-2.rs:27:5
15+
|
16+
LL | v.extend(&v);
17+
| ^^------^--^
18+
| | | |
19+
| | | immutable borrow occurs here
20+
| | immutable borrow later used by call
21+
| mutable borrow occurs here
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0502`.

src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2015.stderr

+1-17
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ LL | v.extend(&v);
2020
| | immutable borrow later used by call
2121
| mutable borrow occurs here
2222

23-
warning: cannot borrow `v` as mutable because it is also borrowed as immutable
24-
--> $DIR/two-phase-reservation-sharing-interference-2.rs:40:5
25-
|
26-
LL | let shared = &v;
27-
| -- immutable borrow occurs here
28-
LL |
29-
LL | v.push(shared.len());
30-
| ^^^^^^^------------^
31-
| | |
32-
| | immutable borrow later used here
33-
| mutable borrow occurs here
34-
|
35-
= note: `#[warn(mutable_borrow_reservation_conflict)]` on by default
36-
= warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future
37-
= note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
38-
39-
error: aborting due to 2 previous errors; 1 warning emitted
23+
error: aborting due to 2 previous errors
4024

4125
For more information about this error, try `rustc --explain E0502`.

src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.migrate2018.stderr

+1-17
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ LL | v.extend(&v);
2020
| | immutable borrow later used by call
2121
| mutable borrow occurs here
2222

23-
warning: cannot borrow `v` as mutable because it is also borrowed as immutable
24-
--> $DIR/two-phase-reservation-sharing-interference-2.rs:40:5
25-
|
26-
LL | let shared = &v;
27-
| -- immutable borrow occurs here
28-
LL |
29-
LL | v.push(shared.len());
30-
| ^^^^^^^------------^
31-
| | |
32-
| | immutable borrow later used here
33-
| mutable borrow occurs here
34-
|
35-
= note: `#[warn(mutable_borrow_reservation_conflict)]` on by default
36-
= warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future
37-
= note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
38-
39-
error: aborting due to 2 previous errors; 1 warning emitted
23+
error: aborting due to 2 previous errors
4024

4125
For more information about this error, try `rustc --explain E0502`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
2+
--> $DIR/two-phase-reservation-sharing-interference-2.rs:19:5
3+
|
4+
LL | let shared = &v;
5+
| -- immutable borrow occurs here
6+
LL |
7+
LL | v.extend(shared);
8+
| ^^------^^^^^^^^
9+
| | |
10+
| | immutable borrow later used by call
11+
| mutable borrow occurs here
12+
13+
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
14+
--> $DIR/two-phase-reservation-sharing-interference-2.rs:27:5
15+
|
16+
LL | v.extend(&v);
17+
| ^^------^--^
18+
| | | |
19+
| | | immutable borrow occurs here
20+
| | immutable borrow later used by call
21+
| mutable borrow occurs here
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0502`.

src/test/ui/borrowck/two-phase-reservation-sharing-interference-2.nll2015.stderr

+4-16
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ LL | let shared = &v;
55
| -- immutable borrow occurs here
66
LL |
77
LL | v.extend(shared);
8-
| ^^^^^^^^^------^
9-
| | |
10-
| | immutable borrow later used here
8+
| ^^------^^^^^^^^
9+
| | |
10+
| | immutable borrow later used by call
1111
| mutable borrow occurs here
1212

1313
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
@@ -20,18 +20,6 @@ LL | v.extend(&v);
2020
| | immutable borrow later used by call
2121
| mutable borrow occurs here
2222

23-
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
24-
--> $DIR/two-phase-reservation-sharing-interference-2.rs:40:5
25-
|
26-
LL | let shared = &v;
27-
| -- immutable borrow occurs here
28-
LL |
29-
LL | v.push(shared.len());
30-
| ^^^^^^^------------^
31-
| | |
32-
| | immutable borrow later used here
33-
| mutable borrow occurs here
34-
35-
error: aborting due to 3 previous errors
23+
error: aborting due to 2 previous errors
3624

3725
For more information about this error, try `rustc --explain E0502`.

0 commit comments

Comments
 (0)