Skip to content

Commit 074f239

Browse files
pnkfelixmatthewjasper
authored andcommitted
add mutable_borrow_reservation_conflict future-incompatibility lint.
Convert the new 2-phase reservation errors into instances of the lint so that they will be controlled by that attribute.
1 parent c0c3c00 commit 074f239

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/librustc/lint/builtin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ declare_lint! {
392392
"nested occurrence of `impl Trait` type"
393393
}
394394

395+
declare_lint! {
396+
pub MUTABLE_BORROW_RESERVATION_CONFLICT,
397+
Warn,
398+
"reservation of a two-phased borrow conflicts with other shared borrows"
399+
}
400+
395401
declare_lint_pass! {
396402
/// Does nothing as a lint pass, but registers some `Lint`s
397403
/// that are used by other parts of the compiler.
@@ -457,6 +463,7 @@ declare_lint_pass! {
457463
AMBIGUOUS_ASSOCIATED_ITEMS,
458464
NESTED_IMPL_TRAIT,
459465
DUPLICATE_MATCHER_BINDING_NAME,
466+
MUTABLE_BORROW_RESERVATION_CONFLICT,
460467
]
461468
}
462469

src/librustc_lint/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
438438
reference: "issue #59014 <https://github.com/rust-lang/rust/issues/59014>",
439439
edition: None,
440440
},
441+
FutureIncompatibleInfo {
442+
id: LintId::of(MUTABLE_BORROW_RESERVATION_CONFLICT),
443+
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
444+
edition: None,
445+
}
441446
]);
442447

443448
// Register renamed and removed lints.

src/librustc_mir/borrow_check/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc::hir::Node;
66
use rustc::hir::def_id::DefId;
77
use rustc::infer::InferCtxt;
88
use rustc::lint::builtin::UNUSED_MUT;
9+
use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT};
910
use rustc::middle::borrowck::SignalledError;
1011
use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
1112
use rustc::mir::{
@@ -26,7 +27,7 @@ use std::collections::BTreeMap;
2627
use std::mem;
2728
use std::rc::Rc;
2829

29-
use syntax_pos::Span;
30+
use syntax_pos::{Span, DUMMY_SP};
3031

3132
use crate::dataflow::indexes::{BorrowIndex, InitIndex, MoveOutIndex, MovePathIndex};
3233
use crate::dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MoveError};
@@ -262,11 +263,19 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
262263
}
263264
mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer
264265

265-
// Buffer any reservation warnings.
266+
// Convert any reservation warnings into lints.
266267
let reservation_warnings = mem::replace(&mut mbcx.reservation_warnings, Default::default());
267268
for (_, (place, span, context, bk, borrow)) in reservation_warnings {
268-
let mut diag = mbcx.report_conflicting_borrow(context, (&place, span), bk, &borrow);
269-
downgrade_if_error(&mut diag);
269+
let mut initial_diag = mbcx.report_conflicting_borrow(context, (&place, span), bk, &borrow);
270+
271+
// Span and message don't matter; we overwrite them below anyway
272+
let mut diag = mbcx.infcx.tcx.struct_span_lint_hir(
273+
MUTABLE_BORROW_RESERVATION_CONFLICT, id, DUMMY_SP, "");
274+
275+
diag.message = initial_diag.styled_message().clone();
276+
diag.span = initial_diag.span.clone();
277+
278+
initial_diag.cancel();
270279
diag.buffer(&mut mbcx.errors_buffer);
271280
}
272281

0 commit comments

Comments
 (0)