Remove BorrowckErrors trait

Its methods are now inherent methods of `MirBorrowckCtxt`
This commit is contained in:
Matthew Jasper 2019-07-12 20:37:06 +01:00
parent 37a99038d0
commit 2cc2b942cf
6 changed files with 110 additions and 136 deletions

View File

@ -22,7 +22,7 @@ use super::{InitializationRequiringAction, PrefixSet};
use super::error_reporting::{IncludingDowncast, UseSpans}; use super::error_reporting::{IncludingDowncast, UseSpans};
use crate::dataflow::drop_flag_effects; use crate::dataflow::drop_flag_effects;
use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex}; use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex};
use crate::util::borrowck_errors::BorrowckErrors; use crate::util::borrowck_errors;
#[derive(Debug)] #[derive(Debug)]
struct MoveSite { struct MoveSite {
@ -89,7 +89,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some(name) => format!("`{}`", name), Some(name) => format!("`{}`", name),
None => "value".to_owned(), None => "value".to_owned(),
}; };
let mut err = self.infcx.tcx.cannot_act_on_uninitialized_variable( let mut err = self.cannot_act_on_uninitialized_variable(
span, span,
desired_action.as_noun(), desired_action.as_noun(),
&self.describe_place_with_options(moved_place, IncludingDowncast(true)) &self.describe_place_with_options(moved_place, IncludingDowncast(true))
@ -119,7 +119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let msg = ""; //FIXME: add "partially " or "collaterally " let msg = ""; //FIXME: add "partially " or "collaterally "
let mut err = self.infcx.tcx.cannot_act_on_moved_value( let mut err = self.cannot_act_on_moved_value(
span, span,
desired_action.as_noun(), desired_action.as_noun(),
msg, msg,
@ -265,7 +265,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
"report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}", "report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}",
location, place, span, borrow location, place, span, borrow
); );
let tcx = self.infcx.tcx;
let value_msg = match self.describe_place(place) { let value_msg = match self.describe_place(place) {
Some(name) => format!("`{}`", name), Some(name) => format!("`{}`", name),
None => "value".to_owned(), None => "value".to_owned(),
@ -281,7 +280,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let move_spans = self.move_spans(place, location); let move_spans = self.move_spans(place, location);
let span = move_spans.args_or_use(); let span = move_spans.args_or_use();
let mut err = tcx.cannot_move_when_borrowed( let mut err = self.cannot_move_when_borrowed(
span, span,
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()), &self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
); );
@ -312,8 +311,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(place, _span): (&Place<'tcx>, Span), (place, _span): (&Place<'tcx>, Span),
borrow: &BorrowData<'tcx>, borrow: &BorrowData<'tcx>,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let tcx = self.infcx.tcx;
let borrow_spans = self.retrieve_borrow_spans(borrow); let borrow_spans = self.retrieve_borrow_spans(borrow);
let borrow_span = borrow_spans.args_or_use(); let borrow_span = borrow_spans.args_or_use();
@ -322,7 +319,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let use_spans = self.move_spans(place, location); let use_spans = self.move_spans(place, location);
let span = use_spans.var_or_use(); let span = use_spans.var_or_use();
let mut err = tcx.cannot_use_when_mutably_borrowed( let mut err = self.cannot_use_when_mutably_borrowed(
span, span,
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()), &self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
borrow_span, borrow_span,
@ -372,7 +369,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}; };
// FIXME: supply non-"" `opt_via` when appropriate // FIXME: supply non-"" `opt_via` when appropriate
let tcx = self.infcx.tcx;
let first_borrow_desc; let first_borrow_desc;
let mut err = match ( let mut err = match (
gen_borrow_kind, gen_borrow_kind,
@ -384,7 +380,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) { ) {
(BorrowKind::Shared, lft, _, BorrowKind::Mut { .. }, _, rgt) => { (BorrowKind::Shared, lft, _, BorrowKind::Mut { .. }, _, rgt) => {
first_borrow_desc = "mutable "; first_borrow_desc = "mutable ";
tcx.cannot_reborrow_already_borrowed( self.cannot_reborrow_already_borrowed(
span, span,
&desc_place, &desc_place,
&msg_place, &msg_place,
@ -398,7 +394,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
(BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => { (BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => {
first_borrow_desc = "immutable "; first_borrow_desc = "immutable ";
tcx.cannot_reborrow_already_borrowed( self.cannot_reborrow_already_borrowed(
span, span,
&desc_place, &desc_place,
&msg_place, &msg_place,
@ -413,7 +409,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(BorrowKind::Mut { .. }, _, _, BorrowKind::Mut { .. }, _, _) => { (BorrowKind::Mut { .. }, _, _, BorrowKind::Mut { .. }, _, _) => {
first_borrow_desc = "first "; first_borrow_desc = "first ";
tcx.cannot_mutably_borrow_multiply( self.cannot_mutably_borrow_multiply(
span, span,
&desc_place, &desc_place,
&msg_place, &msg_place,
@ -425,7 +421,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) => { (BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) => {
first_borrow_desc = "first "; first_borrow_desc = "first ";
tcx.cannot_uniquely_borrow_by_two_closures( self.cannot_uniquely_borrow_by_two_closures(
span, span,
&desc_place, &desc_place,
issued_span, issued_span,
@ -435,7 +431,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(BorrowKind::Mut { .. }, _, _, BorrowKind::Shallow, _, _) (BorrowKind::Mut { .. }, _, _, BorrowKind::Shallow, _, _)
| (BorrowKind::Unique, _, _, BorrowKind::Shallow, _, _) => { | (BorrowKind::Unique, _, _, BorrowKind::Shallow, _, _) => {
let mut err = tcx.cannot_mutate_in_match_guard( let mut err = self.cannot_mutate_in_match_guard(
span, span,
issued_span, issued_span,
&desc_place, &desc_place,
@ -453,7 +449,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(BorrowKind::Unique, _, _, _, _, _) => { (BorrowKind::Unique, _, _, _, _, _) => {
first_borrow_desc = "first "; first_borrow_desc = "first ";
tcx.cannot_uniquely_borrow_by_one_closure( self.cannot_uniquely_borrow_by_one_closure(
span, span,
container_name, container_name,
&desc_place, &desc_place,
@ -467,7 +463,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => { (BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => {
first_borrow_desc = "first "; first_borrow_desc = "first ";
tcx.cannot_reborrow_already_uniquely_borrowed( self.cannot_reborrow_already_uniquely_borrowed(
span, span,
container_name, container_name,
&desc_place, &desc_place,
@ -482,7 +478,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(BorrowKind::Mut { .. }, _, lft, BorrowKind::Unique, _, _) => { (BorrowKind::Mut { .. }, _, lft, BorrowKind::Unique, _, _) => {
first_borrow_desc = "first "; first_borrow_desc = "first ";
tcx.cannot_reborrow_already_uniquely_borrowed( self.cannot_reborrow_already_uniquely_borrowed(
span, span,
container_name, container_name,
&desc_place, &desc_place,
@ -821,7 +817,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
} }
let mut err = self.infcx.tcx.path_does_not_live_long_enough( let mut err = self.path_does_not_live_long_enough(
borrow_span, borrow_span,
&format!("`{}`", name), &format!("`{}`", name),
); );
@ -912,9 +908,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let borrow_spans = self.retrieve_borrow_spans(borrow); let borrow_spans = self.retrieve_borrow_spans(borrow);
let borrow_span = borrow_spans.var_or_use(); let borrow_span = borrow_spans.var_or_use();
let mut err = self.infcx let mut err = self.cannot_borrow_across_destructor(borrow_span);
.tcx
.cannot_borrow_across_destructor(borrow_span);
let what_was_dropped = match self.describe_place(place) { let what_was_dropped = match self.describe_place(place) {
Some(name) => format!("`{}`", name.as_str()), Some(name) => format!("`{}`", name.as_str()),
@ -965,9 +959,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
drop_span, borrow_span drop_span, borrow_span
); );
let mut err = self.infcx let mut err = self.thread_local_value_does_not_live_long_enough(borrow_span);
.tcx
.thread_local_value_does_not_live_long_enough(borrow_span);
err.span_label( err.span_label(
borrow_span, borrow_span,
@ -1011,8 +1003,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
} }
let tcx = self.infcx.tcx; let mut err = self.temporary_value_borrowed_for_too_long(proper_span);
let mut err = tcx.temporary_value_borrowed_for_too_long(proper_span);
err.span_label( err.span_label(
proper_span, proper_span,
"creates a temporary which is freed while still in use", "creates a temporary which is freed while still in use",
@ -1055,8 +1046,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
category: ConstraintCategory, category: ConstraintCategory,
opt_place_desc: Option<&String>, opt_place_desc: Option<&String>,
) -> Option<DiagnosticBuilder<'cx>> { ) -> Option<DiagnosticBuilder<'cx>> {
let tcx = self.infcx.tcx;
let return_kind = match category { let return_kind = match category {
ConstraintCategory::Return => "return", ConstraintCategory::Return => "return",
ConstraintCategory::Yield => "yield", ConstraintCategory::Yield => "yield",
@ -1119,7 +1108,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
}; };
let mut err = tcx.cannot_return_reference_to_local( let mut err = self.cannot_return_reference_to_local(
return_span, return_span,
return_kind, return_kind,
reference_desc, reference_desc,
@ -1144,7 +1133,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let mut err = tcx.cannot_capture_in_long_lived_closure( let mut err = self.cannot_capture_in_long_lived_closure(
args_span, args_span,
captured_var, captured_var,
var_span, var_span,
@ -1203,7 +1192,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
"function" "function"
}; };
let mut err = tcx.borrowed_data_escapes_closure(escape_span, escapes_from); let mut err = borrowck_errors::borrowed_data_escapes_closure(
tcx,
escape_span,
escapes_from,
);
err.span_label( err.span_label(
upvar_span, upvar_span,
@ -1345,9 +1338,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let loan_spans = self.retrieve_borrow_spans(loan); let loan_spans = self.retrieve_borrow_spans(loan);
let loan_span = loan_spans.args_or_use(); let loan_span = loan_spans.args_or_use();
let tcx = self.infcx.tcx;
if loan.kind == BorrowKind::Shallow { if loan.kind == BorrowKind::Shallow {
let mut err = tcx.cannot_mutate_in_match_guard( let mut err = self.cannot_mutate_in_match_guard(
span, span,
loan_span, loan_span,
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()), &self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
@ -1363,7 +1355,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return; return;
} }
let mut err = tcx.cannot_assign_to_borrowed( let mut err = self.cannot_assign_to_borrowed(
span, span,
loan_span, loan_span,
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()), &self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
@ -1427,7 +1419,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some(decl) => (self.describe_place(err_place), decl.source_info.span), Some(decl) => (self.describe_place(err_place), decl.source_info.span),
}; };
let mut err = self.infcx.tcx.cannot_reassign_immutable( let mut err = self.cannot_reassign_immutable(
span, span,
place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"), place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"),
from_arg, from_arg,

View File

@ -41,7 +41,6 @@ use crate::dataflow::MoveDataParamEnv;
use crate::dataflow::{do_dataflow, DebugFormatted}; use crate::dataflow::{do_dataflow, DebugFormatted};
use crate::dataflow::EverInitializedPlaces; use crate::dataflow::EverInitializedPlaces;
use crate::dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; use crate::dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
use crate::util::borrowck_errors::BorrowckErrors;
use self::borrow_set::{BorrowData, BorrowSet}; use self::borrow_set::{BorrowData, BorrowSet};
use self::flows::Flows; use self::flows::Flows;
@ -423,7 +422,7 @@ fn downgrade_if_error(diag: &mut Diagnostic) {
} }
pub struct MirBorrowckCtxt<'cx, 'tcx> { pub struct MirBorrowckCtxt<'cx, 'tcx> {
infcx: &'cx InferCtxt<'cx, 'tcx>, pub(crate) infcx: &'cx InferCtxt<'cx, 'tcx>,
body: &'cx Body<'tcx>, body: &'cx Body<'tcx>,
mir_def_id: DefId, mir_def_id: DefId,
move_data: &'cx MoveData<'tcx>, move_data: &'cx MoveData<'tcx>,
@ -1499,8 +1498,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
debug!("check_for_local_borrow({:?})", borrow); debug!("check_for_local_borrow({:?})", borrow);
if borrow_of_local_data(&borrow.borrowed_place) { if borrow_of_local_data(&borrow.borrowed_place) {
let err = self.infcx.tcx let err = self.cannot_borrow_across_generator_yield(
.cannot_borrow_across_generator_yield(
self.retrieve_borrow_spans(borrow).var_or_use(), self.retrieve_borrow_spans(borrow).var_or_use(),
yield_span, yield_span,
); );

View File

@ -12,7 +12,6 @@ use crate::dataflow::move_paths::{
IllegalMoveOrigin, IllegalMoveOriginKind, IllegalMoveOrigin, IllegalMoveOriginKind,
LookupResult, MoveError, MovePathIndex, LookupResult, MoveError, MovePathIndex,
}; };
use crate::util::borrowck_errors::BorrowckErrors;
// Often when desugaring a pattern match we may have many individual moves in // Often when desugaring a pattern match we may have many individual moves in
// MIR that are all part of one operation from the user's point-of-view. For // MIR that are all part of one operation from the user's point-of-view. For
@ -254,11 +253,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
) )
} }
IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } => { IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } => {
self.infcx.tcx self.cannot_move_out_of_interior_of_drop(span, ty)
.cannot_move_out_of_interior_of_drop(span, ty)
} }
IllegalMoveOriginKind::InteriorOfSliceOrArray { ty, is_index } => IllegalMoveOriginKind::InteriorOfSliceOrArray { ty, is_index } =>
self.infcx.tcx.cannot_move_out_of_interior_noncopy( self.cannot_move_out_of_interior_noncopy(
span, ty, Some(*is_index), span, ty, Some(*is_index),
), ),
}, },
@ -293,7 +291,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
) )
}; };
self.infcx.tcx.cannot_move_out_of(span, &description) self.cannot_move_out_of(span, &description)
} }
fn report_cannot_move_from_borrowed_content( fn report_cannot_move_from_borrowed_content(
@ -317,7 +315,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let Place::Base(PlaceBase::Local(local)) = *deref_base { if let Place::Base(PlaceBase::Local(local)) = *deref_base {
let decl = &self.body.local_decls[local]; let decl = &self.body.local_decls[local];
if decl.is_ref_for_guard() { if decl.is_ref_for_guard() {
let mut err = self.infcx.tcx.cannot_move_out_of( let mut err = self.cannot_move_out_of(
span, span,
&format!("`{}` in pattern guard", decl.name.unwrap()), &format!("`{}` in pattern guard", decl.name.unwrap()),
); );
@ -331,7 +329,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
debug!("report: ty={:?}", ty); debug!("report: ty={:?}", ty);
let mut err = match ty.sty { let mut err = match ty.sty {
ty::Array(..) | ty::Slice(..) => ty::Array(..) | ty::Slice(..) =>
self.infcx.tcx.cannot_move_out_of_interior_noncopy(span, ty, None), self.cannot_move_out_of_interior_noncopy(span, ty, None),
ty::Closure(def_id, closure_substs) ty::Closure(def_id, closure_substs)
if def_id == self.mir_def_id && upvar_field.is_some() if def_id == self.mir_def_id && upvar_field.is_some()
=> { => {
@ -373,7 +371,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
closure_kind_ty, closure_kind, place_description, closure_kind_ty, closure_kind, place_description,
); );
let mut diag = self.infcx.tcx.cannot_move_out_of(span, &place_description); let mut diag = self.cannot_move_out_of(span, &place_description);
diag.span_label(upvar_span, "captured outer variable"); diag.span_label(upvar_span, "captured outer variable");
@ -383,13 +381,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let source = self.borrowed_content_source(deref_base); let source = self.borrowed_content_source(deref_base);
match (self.describe_place(move_place), source.describe_for_named_place()) { match (self.describe_place(move_place), source.describe_for_named_place()) {
(Some(place_desc), Some(source_desc)) => { (Some(place_desc), Some(source_desc)) => {
self.infcx.tcx.cannot_move_out_of( self.cannot_move_out_of(
span, span,
&format!("`{}` which is behind a {}", place_desc, source_desc), &format!("`{}` which is behind a {}", place_desc, source_desc),
) )
} }
(_, _) => { (_, _) => {
self.infcx.tcx.cannot_move_out_of( self.cannot_move_out_of(
span, span,
&source.describe_for_unnamed_place(), &source.describe_for_unnamed_place(),
) )

View File

@ -9,7 +9,6 @@ use syntax_pos::symbol::kw;
use crate::borrow_check::MirBorrowckCtxt; use crate::borrow_check::MirBorrowckCtxt;
use crate::borrow_check::error_reporting::BorrowedContentSource; use crate::borrow_check::error_reporting::BorrowedContentSource;
use crate::util::borrowck_errors::BorrowckErrors;
use crate::util::collect_writes::FindAssignments; use crate::util::collect_writes::FindAssignments;
use crate::util::suggest_ref_mut; use crate::util::suggest_ref_mut;
use rustc_errors::Applicability; use rustc_errors::Applicability;
@ -161,13 +160,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let span = match error_access { let span = match error_access {
AccessKind::Move => { AccessKind::Move => {
err = self.infcx.tcx.cannot_move_out_of(span, &(item_msg + &reason)); err = self.cannot_move_out_of(span, &(item_msg + &reason));
err.span_label(span, "cannot move"); err.span_label(span, "cannot move");
err.buffer(&mut self.errors_buffer); err.buffer(&mut self.errors_buffer);
return; return;
} }
AccessKind::Mutate => { AccessKind::Mutate => {
err = self.infcx.tcx.cannot_assign(span, &(item_msg + &reason)); err = self.cannot_assign(span, &(item_msg + &reason));
act = "assign"; act = "assign";
acted_on = "written"; acted_on = "written";
span span
@ -178,7 +177,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let borrow_spans = self.borrow_spans(span, location); let borrow_spans = self.borrow_spans(span, location);
let borrow_span = borrow_spans.args_or_use(); let borrow_span = borrow_spans.args_or_use();
err = self.infcx.tcx.cannot_borrow_path_as_mutable_because( err = self.cannot_borrow_path_as_mutable_because(
borrow_span, borrow_span,
&item_msg, &item_msg,
&reason, &reason,

View File

@ -4,8 +4,8 @@ use crate::borrow_check::nll::region_infer::RegionInferenceContext;
use crate::borrow_check::nll::type_check::Locations; use crate::borrow_check::nll::type_check::Locations;
use crate::borrow_check::nll::universal_regions::DefiningTy; use crate::borrow_check::nll::universal_regions::DefiningTy;
use crate::borrow_check::nll::ConstraintDescription; use crate::borrow_check::nll::ConstraintDescription;
use crate::util::borrowck_errors::BorrowckErrors;
use crate::borrow_check::Upvar; use crate::borrow_check::Upvar;
use crate::util::borrowck_errors;
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
use rustc::infer::error_reporting::nice_region_error::NiceRegionError; use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
use rustc::infer::InferCtxt; use rustc::infer::InferCtxt;
@ -487,9 +487,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
); );
} }
let mut diag = infcx let mut diag = borrowck_errors::borrowed_data_escapes_closure(
.tcx infcx.tcx,
.borrowed_data_escapes_closure(span, escapes_from); span,
escapes_from,
);
if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span { if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
diag.span_label( diag.span_label(

View File

@ -2,18 +2,9 @@ use rustc::ty::{self, Ty, TyCtxt};
use rustc_errors::{DiagnosticBuilder, DiagnosticId}; use rustc_errors::{DiagnosticBuilder, DiagnosticId};
use syntax_pos::{MultiSpan, Span}; use syntax_pos::{MultiSpan, Span};
pub(crate) trait BorrowckErrors<'cx>: Sized + Copy { impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
fn struct_span_err_with_code<S: Into<MultiSpan>>( pub(crate) fn cannot_move_when_borrowed(
self, &self,
sp: S,
msg: &str,
code: DiagnosticId,
) -> DiagnosticBuilder<'cx>;
fn struct_span_err<S: Into<MultiSpan>>(self, sp: S, msg: &str) -> DiagnosticBuilder<'cx>;
fn cannot_move_when_borrowed(
self,
span: Span, span: Span,
desc: &str, desc: &str,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
@ -26,8 +17,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn cannot_use_when_mutably_borrowed( pub(crate) fn cannot_use_when_mutably_borrowed(
self, &self,
span: Span, span: Span,
desc: &str, desc: &str,
borrow_span: Span, borrow_span: Span,
@ -49,8 +40,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_act_on_uninitialized_variable( pub(crate) fn cannot_act_on_uninitialized_variable(
self, &self,
span: Span, span: Span,
verb: &str, verb: &str,
desc: &str, desc: &str,
@ -65,8 +56,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn cannot_mutably_borrow_multiply( pub(crate) fn cannot_mutably_borrow_multiply(
self, &self,
new_loan_span: Span, new_loan_span: Span,
desc: &str, desc: &str,
opt_via: &str, opt_via: &str,
@ -114,8 +105,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_uniquely_borrow_by_two_closures( pub(crate) fn cannot_uniquely_borrow_by_two_closures(
self, &self,
new_loan_span: Span, new_loan_span: Span,
desc: &str, desc: &str,
old_loan_span: Span, old_loan_span: Span,
@ -143,8 +134,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_uniquely_borrow_by_one_closure( pub(crate) fn cannot_uniquely_borrow_by_one_closure(
self, &self,
new_loan_span: Span, new_loan_span: Span,
container_name: &str, container_name: &str,
desc_new: &str, desc_new: &str,
@ -174,8 +165,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_reborrow_already_uniquely_borrowed( pub(crate) fn cannot_reborrow_already_uniquely_borrowed(
self, &self,
new_loan_span: Span, new_loan_span: Span,
container_name: &str, container_name: &str,
desc_new: &str, desc_new: &str,
@ -210,8 +201,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_reborrow_already_borrowed( pub(crate) fn cannot_reborrow_already_borrowed(
self, &self,
span: Span, span: Span,
desc_new: &str, desc_new: &str,
msg_new: &str, msg_new: &str,
@ -263,8 +254,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_assign_to_borrowed( pub(crate) fn cannot_assign_to_borrowed(
self, &self,
span: Span, span: Span,
borrow_span: Span, borrow_span: Span,
desc: &str, desc: &str,
@ -285,8 +276,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_reassign_immutable( pub(crate) fn cannot_reassign_immutable(
self, &self,
span: Span, span: Span,
desc: &str, desc: &str,
is_arg: bool, is_arg: bool,
@ -306,12 +297,12 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn cannot_assign(self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> { pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> {
struct_span_err!(self, span, E0594, "cannot assign to {}", desc) struct_span_err!(self, span, E0594, "cannot assign to {}", desc)
} }
fn cannot_move_out_of( pub(crate) fn cannot_move_out_of(
self, &self,
move_from_span: Span, move_from_span: Span,
move_from_desc: &str, move_from_desc: &str,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
@ -327,8 +318,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
/// Signal an error due to an attempt to move out of the interior /// Signal an error due to an attempt to move out of the interior
/// of an array or slice. `is_index` is None when error origin /// of an array or slice. `is_index` is None when error origin
/// didn't capture whether there was an indexing operation or not. /// didn't capture whether there was an indexing operation or not.
fn cannot_move_out_of_interior_noncopy( pub(crate) fn cannot_move_out_of_interior_noncopy(
self, &self,
move_from_span: Span, move_from_span: Span,
ty: Ty<'_>, ty: Ty<'_>,
is_index: Option<bool>, is_index: Option<bool>,
@ -350,8 +341,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_move_out_of_interior_of_drop( pub(crate) fn cannot_move_out_of_interior_of_drop(
self, &self,
move_from_span: Span, move_from_span: Span,
container_ty: Ty<'_>, container_ty: Ty<'_>,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
@ -366,8 +357,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_act_on_moved_value( pub(crate) fn cannot_act_on_moved_value(
self, &self,
use_span: Span, use_span: Span,
verb: &str, verb: &str,
optional_adverb_for_moved: &str, optional_adverb_for_moved: &str,
@ -388,8 +379,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn cannot_borrow_path_as_mutable_because( pub(crate) fn cannot_borrow_path_as_mutable_because(
self, &self,
span: Span, span: Span,
path: &str, path: &str,
reason: &str, reason: &str,
@ -404,8 +395,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn cannot_mutate_in_match_guard( pub(crate) fn cannot_mutate_in_match_guard(
self, &self,
mutate_span: Span, mutate_span: Span,
match_span: Span, match_span: Span,
match_place: &str, match_place: &str,
@ -424,8 +415,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_borrow_across_generator_yield( pub(crate) fn cannot_borrow_across_generator_yield(
self, &self,
span: Span, span: Span,
yield_span: Span, yield_span: Span,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
@ -439,8 +430,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_borrow_across_destructor( pub(crate) fn cannot_borrow_across_destructor(
self, &self,
borrow_span: Span, borrow_span: Span,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
struct_span_err!( struct_span_err!(
@ -451,8 +442,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn path_does_not_live_long_enough( pub(crate) fn path_does_not_live_long_enough(
self, &self,
span: Span, span: Span,
path: &str, path: &str,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
@ -465,8 +456,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn cannot_return_reference_to_local( pub(crate) fn cannot_return_reference_to_local(
self, &self,
span: Span, span: Span,
return_kind: &str, return_kind: &str,
reference_desc: &str, reference_desc: &str,
@ -490,8 +481,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn cannot_capture_in_long_lived_closure( pub(crate) fn cannot_capture_in_long_lived_closure(
self, &self,
closure_span: Span, closure_span: Span,
borrowed_path: &str, borrowed_path: &str,
capture_span: Span, capture_span: Span,
@ -513,22 +504,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
err err
} }
fn borrowed_data_escapes_closure( pub(crate) fn thread_local_value_does_not_live_long_enough(
self, &self,
escape_span: Span,
escapes_from: &str,
) -> DiagnosticBuilder<'cx> {
struct_span_err!(
self,
escape_span,
E0521,
"borrowed data escapes outside of {}",
escapes_from,
)
}
fn thread_local_value_does_not_live_long_enough(
self,
span: Span, span: Span,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
struct_span_err!( struct_span_err!(
@ -539,8 +516,8 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
) )
} }
fn temporary_value_borrowed_for_too_long( pub(crate) fn temporary_value_borrowed_for_too_long(
self, &self,
span: Span, span: Span,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
struct_span_err!( struct_span_err!(
@ -550,19 +527,27 @@ pub(crate) trait BorrowckErrors<'cx>: Sized + Copy {
"temporary value dropped while borrowed", "temporary value dropped while borrowed",
) )
} }
}
impl BorrowckErrors<'tcx> for TyCtxt<'tcx> {
fn struct_span_err_with_code<S: Into<MultiSpan>>( fn struct_span_err_with_code<S: Into<MultiSpan>>(
self, &self,
sp: S, sp: S,
msg: &str, msg: &str,
code: DiagnosticId, code: DiagnosticId,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
self.sess.struct_span_err_with_code(sp, msg, code) self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)
}
fn struct_span_err<S: Into<MultiSpan>>(self, sp: S, msg: &str) -> DiagnosticBuilder<'tcx> {
self.sess.struct_span_err(sp, msg)
} }
} }
pub(crate) fn borrowed_data_escapes_closure<'tcx>(
tcx: TyCtxt<'tcx>,
escape_span: Span,
escapes_from: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
tcx.sess,
escape_span,
E0521,
"borrowed data escapes outside of {}",
escapes_from,
)
}