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.
This commit is contained in:
Felix S. Klock II 2019-03-13 20:15:58 +01:00 committed by Matthew Jasper
parent c0c3c00c59
commit 074f239781
3 changed files with 25 additions and 4 deletions

View file

@ -392,6 +392,12 @@ declare_lint! {
"nested occurrence of `impl Trait` type"
}
declare_lint! {
pub MUTABLE_BORROW_RESERVATION_CONFLICT,
Warn,
"reservation of a two-phased borrow conflicts with other shared borrows"
}
declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
@ -457,6 +463,7 @@ declare_lint_pass! {
AMBIGUOUS_ASSOCIATED_ITEMS,
NESTED_IMPL_TRAIT,
DUPLICATE_MATCHER_BINDING_NAME,
MUTABLE_BORROW_RESERVATION_CONFLICT,
]
}

View file

@ -438,6 +438,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference: "issue #59014 <https://github.com/rust-lang/rust/issues/59014>",
edition: None,
},
FutureIncompatibleInfo {
id: LintId::of(MUTABLE_BORROW_RESERVATION_CONFLICT),
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
edition: None,
}
]);
// Register renamed and removed lints.

View file

@ -6,6 +6,7 @@ use rustc::hir::Node;
use rustc::hir::def_id::DefId;
use rustc::infer::InferCtxt;
use rustc::lint::builtin::UNUSED_MUT;
use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT};
use rustc::middle::borrowck::SignalledError;
use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
use rustc::mir::{
@ -26,7 +27,7 @@ use std::collections::BTreeMap;
use std::mem;
use std::rc::Rc;
use syntax_pos::Span;
use syntax_pos::{Span, DUMMY_SP};
use crate::dataflow::indexes::{BorrowIndex, InitIndex, MoveOutIndex, MovePathIndex};
use crate::dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MoveError};
@ -262,11 +263,19 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
}
mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer
// Buffer any reservation warnings.
// Convert any reservation warnings into lints.
let reservation_warnings = mem::replace(&mut mbcx.reservation_warnings, Default::default());
for (_, (place, span, context, bk, borrow)) in reservation_warnings {
let mut diag = mbcx.report_conflicting_borrow(context, (&place, span), bk, &borrow);
downgrade_if_error(&mut diag);
let mut initial_diag = mbcx.report_conflicting_borrow(context, (&place, span), bk, &borrow);
// Span and message don't matter; we overwrite them below anyway
let mut diag = mbcx.infcx.tcx.struct_span_lint_hir(
MUTABLE_BORROW_RESERVATION_CONFLICT, id, DUMMY_SP, "");
diag.message = initial_diag.styled_message().clone();
diag.span = initial_diag.span.clone();
initial_diag.cancel();
diag.buffer(&mut mbcx.errors_buffer);
}