Skip to content

Commit 4ff1234

Browse files
authored
Rollup merge of #60452 - JohnTitor:remove-context, r=matthewjasper
Remove Context and ContextKind Fixes #60421 r? @matthewjasper
2 parents 3dfee3a + 99ebb7a commit 4ff1234

File tree

5 files changed

+171
-211
lines changed

5 files changed

+171
-211
lines changed

Diff for: src/librustc_mir/borrow_check/error_reporting.rs

+38-38
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax_pos::Span;
2222
use syntax::source_map::CompilerDesugaringKind;
2323

2424
use super::borrow_set::BorrowData;
25-
use super::{Context, MirBorrowckCtxt};
25+
use super::{MirBorrowckCtxt};
2626
use super::{InitializationRequiringAction, PrefixSet};
2727
use crate::dataflow::drop_flag_effects;
2828
use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex};
@@ -42,22 +42,22 @@ struct MoveSite {
4242
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
4343
pub(super) fn report_use_of_moved_or_uninitialized(
4444
&mut self,
45-
context: Context,
45+
location: Location,
4646
desired_action: InitializationRequiringAction,
4747
(moved_place, used_place, span): (&Place<'tcx>, &Place<'tcx>, Span),
4848
mpi: MovePathIndex,
4949
) {
5050
debug!(
51-
"report_use_of_moved_or_uninitialized: context={:?} desired_action={:?} \
51+
"report_use_of_moved_or_uninitialized: location={:?} desired_action={:?} \
5252
moved_place={:?} used_place={:?} span={:?} mpi={:?}",
53-
context, desired_action, moved_place, used_place, span, mpi
53+
location, desired_action, moved_place, used_place, span, mpi
5454
);
5555

56-
let use_spans = self.move_spans(moved_place, context.loc)
57-
.or_else(|| self.borrow_spans(span, context.loc));
56+
let use_spans = self.move_spans(moved_place, location)
57+
.or_else(|| self.borrow_spans(span, location));
5858
let span = use_spans.args_or_use();
5959

60-
let move_site_vec = self.get_moved_indexes(context, mpi);
60+
let move_site_vec = self.get_moved_indexes(location, mpi);
6161
debug!(
6262
"report_use_of_moved_or_uninitialized: move_site_vec={:?}",
6363
move_site_vec
@@ -125,7 +125,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
125125
);
126126

127127
self.add_moved_or_invoked_closure_note(
128-
context.loc,
128+
location,
129129
used_place,
130130
&mut err,
131131
);
@@ -261,13 +261,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
261261

262262
pub(super) fn report_move_out_while_borrowed(
263263
&mut self,
264-
context: Context,
264+
location: Location,
265265
(place, span): (&Place<'tcx>, Span),
266266
borrow: &BorrowData<'tcx>,
267267
) {
268268
debug!(
269-
"report_move_out_while_borrowed: context={:?} place={:?} span={:?} borrow={:?}",
270-
context, place, span, borrow
269+
"report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}",
270+
location, place, span, borrow
271271
);
272272
let tcx = self.infcx.tcx;
273273
let value_msg = match self.describe_place(place) {
@@ -282,7 +282,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
282282
let borrow_spans = self.retrieve_borrow_spans(borrow);
283283
let borrow_span = borrow_spans.args_or_use();
284284

285-
let move_spans = self.move_spans(place, context.loc);
285+
let move_spans = self.move_spans(place, location);
286286
let span = move_spans.args_or_use();
287287

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

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

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

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

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

346-
self.explain_why_borrow_contains_point(context, borrow, None)
346+
self.explain_why_borrow_contains_point(location, borrow, None)
347347
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "", None);
348348
err
349349
}
350350

351351
pub(super) fn report_conflicting_borrow(
352352
&mut self,
353-
context: Context,
353+
location: Location,
354354
(place, span): (&Place<'tcx>, Span),
355355
gen_borrow_kind: BorrowKind,
356356
issued_borrow: &BorrowData<'tcx>,
357357
) -> DiagnosticBuilder<'cx> {
358358
let issued_spans = self.retrieve_borrow_spans(issued_borrow);
359359
let issued_span = issued_spans.args_or_use();
360360

361-
let borrow_spans = self.borrow_spans(span, context.loc);
361+
let borrow_spans = self.borrow_spans(span, location);
362362
let span = borrow_spans.args_or_use();
363363

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

373-
let explanation = self.explain_why_borrow_contains_point(context, issued_borrow, None);
373+
let explanation = self.explain_why_borrow_contains_point(location, issued_borrow, None);
374374
let second_borrow_desc = if explanation.is_explained() {
375375
"second "
376376
} else {
@@ -671,7 +671,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
671671
/// `Drop::drop` with an aliasing borrow.)
672672
pub(super) fn report_borrowed_value_does_not_live_long_enough(
673673
&mut self,
674-
context: Context,
674+
location: Location,
675675
borrow: &BorrowData<'tcx>,
676676
place_span: (&Place<'tcx>, Span),
677677
kind: Option<WriteKind>,
@@ -680,7 +680,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
680680
"report_borrowed_value_does_not_live_long_enough(\
681681
{:?}, {:?}, {:?}, {:?}\
682682
)",
683-
context, borrow, place_span, kind
683+
location, borrow, place_span, kind
684684
);
685685

686686
let drop_span = place_span.1;
@@ -719,7 +719,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
719719
// destructor conflict.
720720
if !borrow.borrowed_place.is_prefix_of(place_span.0) {
721721
self.report_borrow_conflicts_with_destructor(
722-
context, borrow, place_span, kind, dropped_ty,
722+
location, borrow, place_span, kind, dropped_ty,
723723
);
724724
return;
725725
}
@@ -728,7 +728,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
728728
let place_desc = self.describe_place(&borrow.borrowed_place);
729729

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

733733
let err = match (place_desc, explanation) {
734734
(Some(_), _) if self.is_place_thread_local(root_place) => {
@@ -784,7 +784,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
784784
},
785785
) => self.report_escaping_data(borrow_span, name, upvar_span, upvar_name, span),
786786
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
787-
context,
787+
location,
788788
&name,
789789
&scope_tree,
790790
&borrow,
@@ -793,7 +793,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
793793
explanation,
794794
),
795795
(None, explanation) => self.report_temporary_value_does_not_live_long_enough(
796-
context,
796+
location,
797797
&scope_tree,
798798
&borrow,
799799
drop_span,
@@ -808,7 +808,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
808808

809809
fn report_local_value_does_not_live_long_enough(
810810
&mut self,
811-
context: Context,
811+
location: Location,
812812
name: &str,
813813
scope_tree: &'tcx ScopeTree,
814814
borrow: &BorrowData<'tcx>,
@@ -820,7 +820,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
820820
"report_local_value_does_not_live_long_enough(\
821821
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
822822
)",
823-
context, name, scope_tree, borrow, drop_span, borrow_spans
823+
location, name, scope_tree, borrow, drop_span, borrow_spans
824824
);
825825

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

915915
fn report_borrow_conflicts_with_destructor(
916916
&mut self,
917-
context: Context,
917+
location: Location,
918918
borrow: &BorrowData<'tcx>,
919919
(place, drop_span): (&Place<'tcx>, Span),
920920
kind: Option<WriteKind>,
@@ -924,7 +924,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
924924
"report_borrow_conflicts_with_destructor(\
925925
{:?}, {:?}, ({:?}, {:?}), {:?}\
926926
)",
927-
context, borrow, place, drop_span, kind,
927+
location, borrow, place, drop_span, kind,
928928
);
929929

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

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

999999
fn report_temporary_value_does_not_live_long_enough(
10001000
&mut self,
1001-
context: Context,
1001+
location: Location,
10021002
scope_tree: &'tcx ScopeTree,
10031003
borrow: &BorrowData<'tcx>,
10041004
drop_span: Span,
@@ -1010,7 +1010,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
10101010
"report_temporary_value_does_not_live_long_enough(\
10111011
{:?}, {:?}, {:?}, {:?}, {:?}\
10121012
)",
1013-
context, scope_tree, borrow, drop_span, proper_span
1013+
location, scope_tree, borrow, drop_span, proper_span
10141014
);
10151015

10161016
if let BorrowExplanation::MustBeValidFor {
@@ -1246,12 +1246,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12461246
err
12471247
}
12481248

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

12521252
let mut stack = Vec::new();
1253-
stack.extend(mir.predecessor_locations(context.loc).map(|predecessor| {
1254-
let is_back_edge = context.loc.dominates(predecessor, &self.dominators);
1253+
stack.extend(mir.predecessor_locations(location).map(|predecessor| {
1254+
let is_back_edge = location.dominates(predecessor, &self.dominators);
12551255
(predecessor, is_back_edge)
12561256
}));
12571257

@@ -1348,7 +1348,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13481348

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

1389-
self.explain_why_borrow_contains_point(context, loan, None)
1389+
self.explain_why_borrow_contains_point(location, loan, None)
13901390
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "", None);
13911391

13921392
err.buffer(&mut self.errors_buffer);
@@ -1400,7 +1400,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
14001400
/// assignment to `x.f`).
14011401
pub(super) fn report_illegal_reassignment(
14021402
&mut self,
1403-
_context: Context,
1403+
_location: Location,
14041404
(place, span): (&Place<'tcx>, Span),
14051405
assigned_span: Span,
14061406
err_place: &Place<'tcx>,

0 commit comments

Comments
 (0)