Skip to content
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

Remove Context and ContextKind #60452

Merged
merged 1 commit into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use syntax_pos::Span;
use syntax::source_map::CompilerDesugaringKind;

use super::borrow_set::BorrowData;
use super::{Context, MirBorrowckCtxt};
use super::{MirBorrowckCtxt};
use super::{InitializationRequiringAction, PrefixSet};
use crate::dataflow::drop_flag_effects;
use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex};
Expand All @@ -42,22 +42,22 @@ struct MoveSite {
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
pub(super) fn report_use_of_moved_or_uninitialized(
&mut self,
context: Context,
location: Location,
desired_action: InitializationRequiringAction,
(moved_place, used_place, span): (&Place<'tcx>, &Place<'tcx>, Span),
mpi: MovePathIndex,
) {
debug!(
"report_use_of_moved_or_uninitialized: context={:?} desired_action={:?} \
"report_use_of_moved_or_uninitialized: location={:?} desired_action={:?} \
moved_place={:?} used_place={:?} span={:?} mpi={:?}",
context, desired_action, moved_place, used_place, span, mpi
location, desired_action, moved_place, used_place, span, mpi
);

let use_spans = self.move_spans(moved_place, context.loc)
.or_else(|| self.borrow_spans(span, context.loc));
let use_spans = self.move_spans(moved_place, location)
.or_else(|| self.borrow_spans(span, location));
let span = use_spans.args_or_use();

let move_site_vec = self.get_moved_indexes(context, mpi);
let move_site_vec = self.get_moved_indexes(location, mpi);
debug!(
"report_use_of_moved_or_uninitialized: move_site_vec={:?}",
move_site_vec
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
);

self.add_moved_or_invoked_closure_note(
context.loc,
location,
used_place,
&mut err,
);
Expand Down Expand Up @@ -261,13 +261,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

pub(super) fn report_move_out_while_borrowed(
&mut self,
context: Context,
location: Location,
(place, span): (&Place<'tcx>, Span),
borrow: &BorrowData<'tcx>,
) {
debug!(
"report_move_out_while_borrowed: context={:?} place={:?} span={:?} borrow={:?}",
context, place, span, borrow
"report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}",
location, place, span, borrow
);
let tcx = self.infcx.tcx;
let value_msg = match self.describe_place(place) {
Expand All @@ -282,7 +282,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let borrow_spans = self.retrieve_borrow_spans(borrow);
let borrow_span = borrow_spans.args_or_use();

let move_spans = self.move_spans(place, context.loc);
let move_spans = self.move_spans(place, location);
let span = move_spans.args_or_use();

let mut err = tcx.cannot_move_when_borrowed(
Expand All @@ -304,7 +304,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
);

self.explain_why_borrow_contains_point(
context,
location,
borrow,
None,
).add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "", Some(borrow_span));
Expand All @@ -313,7 +313,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

pub(super) fn report_use_while_mutably_borrowed(
&mut self,
context: Context,
location: Location,
(place, _span): (&Place<'tcx>, Span),
borrow: &BorrowData<'tcx>,
) -> DiagnosticBuilder<'cx> {
Expand All @@ -324,7 +324,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

// Conflicting borrows are reported separately, so only check for move
// captures.
let use_spans = self.move_spans(place, context.loc);
let use_spans = self.move_spans(place, location);
let span = use_spans.var_or_use();

let mut err = tcx.cannot_use_when_mutably_borrowed(
Expand All @@ -343,22 +343,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
format!("borrow occurs due to use of `{}`{}", desc_place, borrow_spans.describe())
});

self.explain_why_borrow_contains_point(context, borrow, None)
self.explain_why_borrow_contains_point(location, borrow, None)
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "", None);
err
}

pub(super) fn report_conflicting_borrow(
&mut self,
context: Context,
location: Location,
(place, span): (&Place<'tcx>, Span),
gen_borrow_kind: BorrowKind,
issued_borrow: &BorrowData<'tcx>,
) -> DiagnosticBuilder<'cx> {
let issued_spans = self.retrieve_borrow_spans(issued_borrow);
let issued_span = issued_spans.args_or_use();

let borrow_spans = self.borrow_spans(span, context.loc);
let borrow_spans = self.borrow_spans(span, location);
let span = borrow_spans.args_or_use();

let container_name = if issued_spans.for_generator() || borrow_spans.for_generator() {
Expand All @@ -370,7 +370,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let (desc_place, msg_place, msg_borrow, union_type_name) =
self.describe_place_for_conflicting_borrow(place, &issued_borrow.borrowed_place);

let explanation = self.explain_why_borrow_contains_point(context, issued_borrow, None);
let explanation = self.explain_why_borrow_contains_point(location, issued_borrow, None);
let second_borrow_desc = if explanation.is_explained() {
"second "
} else {
Expand Down Expand Up @@ -671,7 +671,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
/// `Drop::drop` with an aliasing borrow.)
pub(super) fn report_borrowed_value_does_not_live_long_enough(
&mut self,
context: Context,
location: Location,
borrow: &BorrowData<'tcx>,
place_span: (&Place<'tcx>, Span),
kind: Option<WriteKind>,
Expand All @@ -680,7 +680,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
"report_borrowed_value_does_not_live_long_enough(\
{:?}, {:?}, {:?}, {:?}\
)",
context, borrow, place_span, kind
location, borrow, place_span, kind
);

let drop_span = place_span.1;
Expand Down Expand Up @@ -719,7 +719,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
// destructor conflict.
if !borrow.borrowed_place.is_prefix_of(place_span.0) {
self.report_borrow_conflicts_with_destructor(
context, borrow, place_span, kind, dropped_ty,
location, borrow, place_span, kind, dropped_ty,
);
return;
}
Expand All @@ -728,7 +728,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let place_desc = self.describe_place(&borrow.borrowed_place);

let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
let explanation = self.explain_why_borrow_contains_point(context, &borrow, kind_place);
let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);

let err = match (place_desc, explanation) {
(Some(_), _) if self.is_place_thread_local(root_place) => {
Expand Down Expand Up @@ -784,7 +784,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
},
) => self.report_escaping_data(borrow_span, name, upvar_span, upvar_name, span),
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
context,
location,
&name,
&scope_tree,
&borrow,
Expand All @@ -793,7 +793,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
explanation,
),
(None, explanation) => self.report_temporary_value_does_not_live_long_enough(
context,
location,
&scope_tree,
&borrow,
drop_span,
Expand All @@ -808,7 +808,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

fn report_local_value_does_not_live_long_enough(
&mut self,
context: Context,
location: Location,
name: &str,
scope_tree: &'tcx ScopeTree,
borrow: &BorrowData<'tcx>,
Expand All @@ -820,7 +820,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
"report_local_value_does_not_live_long_enough(\
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
)",
context, name, scope_tree, borrow, drop_span, borrow_spans
location, name, scope_tree, borrow, drop_span, borrow_spans
);

let borrow_span = borrow_spans.var_or_use();
Expand Down Expand Up @@ -914,7 +914,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

fn report_borrow_conflicts_with_destructor(
&mut self,
context: Context,
location: Location,
borrow: &BorrowData<'tcx>,
(place, drop_span): (&Place<'tcx>, Span),
kind: Option<WriteKind>,
Expand All @@ -924,7 +924,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
"report_borrow_conflicts_with_destructor(\
{:?}, {:?}, ({:?}, {:?}), {:?}\
)",
context, borrow, place, drop_span, kind,
location, borrow, place, drop_span, kind,
);

let borrow_spans = self.retrieve_borrow_spans(borrow);
Expand Down Expand Up @@ -957,7 +957,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

// Only give this note and suggestion if they could be relevant.
let explanation =
self.explain_why_borrow_contains_point(context, borrow, kind.map(|k| (k, place)));
self.explain_why_borrow_contains_point(location, borrow, kind.map(|k| (k, place)));
match explanation {
BorrowExplanation::UsedLater { .. }
| BorrowExplanation::UsedLaterWhenDropped { .. } => {
Expand Down Expand Up @@ -998,7 +998,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

fn report_temporary_value_does_not_live_long_enough(
&mut self,
context: Context,
location: Location,
scope_tree: &'tcx ScopeTree,
borrow: &BorrowData<'tcx>,
drop_span: Span,
Expand All @@ -1010,7 +1010,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
"report_temporary_value_does_not_live_long_enough(\
{:?}, {:?}, {:?}, {:?}, {:?}\
)",
context, scope_tree, borrow, drop_span, proper_span
location, scope_tree, borrow, drop_span, proper_span
);

if let BorrowExplanation::MustBeValidFor {
Expand Down Expand Up @@ -1246,12 +1246,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
err
}

fn get_moved_indexes(&mut self, context: Context, mpi: MovePathIndex) -> Vec<MoveSite> {
fn get_moved_indexes(&mut self, location: Location, mpi: MovePathIndex) -> Vec<MoveSite> {
let mir = self.mir;

let mut stack = Vec::new();
stack.extend(mir.predecessor_locations(context.loc).map(|predecessor| {
let is_back_edge = context.loc.dominates(predecessor, &self.dominators);
stack.extend(mir.predecessor_locations(location).map(|predecessor| {
let is_back_edge = location.dominates(predecessor, &self.dominators);
(predecessor, is_back_edge)
}));

Expand Down Expand Up @@ -1348,7 +1348,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

pub(super) fn report_illegal_mutation_of_borrowed(
&mut self,
context: Context,
location: Location,
(place, span): (&Place<'tcx>, Span),
loan: &BorrowData<'tcx>,
) {
Expand Down Expand Up @@ -1386,7 +1386,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
format!("borrow occurs due to use{}", loan_spans.describe()),
);

self.explain_why_borrow_contains_point(context, loan, None)
self.explain_why_borrow_contains_point(location, loan, None)
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "", None);

err.buffer(&mut self.errors_buffer);
Expand All @@ -1400,7 +1400,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
/// assignment to `x.f`).
pub(super) fn report_illegal_reassignment(
&mut self,
_context: Context,
_location: Location,
(place, span): (&Place<'tcx>, Span),
assigned_span: Span,
err_place: &Place<'tcx>,
Expand Down
Loading