Skip to content

Commit 2cc2b94

Browse files
committed
Remove BorrowckErrors trait
Its methods are now inherent methods of `MirBorrowckCtxt`
1 parent 37a9903 commit 2cc2b94

File tree

6 files changed

+109
-135
lines changed

6 files changed

+109
-135
lines changed

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

+27-35
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::{InitializationRequiringAction, PrefixSet};
2222
use super::error_reporting::{IncludingDowncast, UseSpans};
2323
use crate::dataflow::drop_flag_effects;
2424
use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex};
25-
use crate::util::borrowck_errors::BorrowckErrors;
25+
use crate::util::borrowck_errors;
2626

2727
#[derive(Debug)]
2828
struct MoveSite {
@@ -89,7 +89,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
8989
Some(name) => format!("`{}`", name),
9090
None => "value".to_owned(),
9191
};
92-
let mut err = self.infcx.tcx.cannot_act_on_uninitialized_variable(
92+
let mut err = self.cannot_act_on_uninitialized_variable(
9393
span,
9494
desired_action.as_noun(),
9595
&self.describe_place_with_options(moved_place, IncludingDowncast(true))
@@ -119,7 +119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
119119

120120
let msg = ""; //FIXME: add "partially " or "collaterally "
121121

122-
let mut err = self.infcx.tcx.cannot_act_on_moved_value(
122+
let mut err = self.cannot_act_on_moved_value(
123123
span,
124124
desired_action.as_noun(),
125125
msg,
@@ -265,7 +265,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
265265
"report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}",
266266
location, place, span, borrow
267267
);
268-
let tcx = self.infcx.tcx;
269268
let value_msg = match self.describe_place(place) {
270269
Some(name) => format!("`{}`", name),
271270
None => "value".to_owned(),
@@ -281,7 +280,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
281280
let move_spans = self.move_spans(place, location);
282281
let span = move_spans.args_or_use();
283282

284-
let mut err = tcx.cannot_move_when_borrowed(
283+
let mut err = self.cannot_move_when_borrowed(
285284
span,
286285
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
287286
);
@@ -312,8 +311,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
312311
(place, _span): (&Place<'tcx>, Span),
313312
borrow: &BorrowData<'tcx>,
314313
) -> DiagnosticBuilder<'cx> {
315-
let tcx = self.infcx.tcx;
316-
317314
let borrow_spans = self.retrieve_borrow_spans(borrow);
318315
let borrow_span = borrow_spans.args_or_use();
319316

@@ -322,7 +319,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
322319
let use_spans = self.move_spans(place, location);
323320
let span = use_spans.var_or_use();
324321

325-
let mut err = tcx.cannot_use_when_mutably_borrowed(
322+
let mut err = self.cannot_use_when_mutably_borrowed(
326323
span,
327324
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
328325
borrow_span,
@@ -372,7 +369,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
372369
};
373370

374371
// FIXME: supply non-"" `opt_via` when appropriate
375-
let tcx = self.infcx.tcx;
376372
let first_borrow_desc;
377373
let mut err = match (
378374
gen_borrow_kind,
@@ -384,7 +380,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
384380
) {
385381
(BorrowKind::Shared, lft, _, BorrowKind::Mut { .. }, _, rgt) => {
386382
first_borrow_desc = "mutable ";
387-
tcx.cannot_reborrow_already_borrowed(
383+
self.cannot_reborrow_already_borrowed(
388384
span,
389385
&desc_place,
390386
&msg_place,
@@ -398,7 +394,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
398394
}
399395
(BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => {
400396
first_borrow_desc = "immutable ";
401-
tcx.cannot_reborrow_already_borrowed(
397+
self.cannot_reborrow_already_borrowed(
402398
span,
403399
&desc_place,
404400
&msg_place,
@@ -413,7 +409,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
413409

414410
(BorrowKind::Mut { .. }, _, _, BorrowKind::Mut { .. }, _, _) => {
415411
first_borrow_desc = "first ";
416-
tcx.cannot_mutably_borrow_multiply(
412+
self.cannot_mutably_borrow_multiply(
417413
span,
418414
&desc_place,
419415
&msg_place,
@@ -425,7 +421,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
425421

426422
(BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) => {
427423
first_borrow_desc = "first ";
428-
tcx.cannot_uniquely_borrow_by_two_closures(
424+
self.cannot_uniquely_borrow_by_two_closures(
429425
span,
430426
&desc_place,
431427
issued_span,
@@ -435,7 +431,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
435431

436432
(BorrowKind::Mut { .. }, _, _, BorrowKind::Shallow, _, _)
437433
| (BorrowKind::Unique, _, _, BorrowKind::Shallow, _, _) => {
438-
let mut err = tcx.cannot_mutate_in_match_guard(
434+
let mut err = self.cannot_mutate_in_match_guard(
439435
span,
440436
issued_span,
441437
&desc_place,
@@ -453,7 +449,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
453449

454450
(BorrowKind::Unique, _, _, _, _, _) => {
455451
first_borrow_desc = "first ";
456-
tcx.cannot_uniquely_borrow_by_one_closure(
452+
self.cannot_uniquely_borrow_by_one_closure(
457453
span,
458454
container_name,
459455
&desc_place,
@@ -467,7 +463,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
467463

468464
(BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => {
469465
first_borrow_desc = "first ";
470-
tcx.cannot_reborrow_already_uniquely_borrowed(
466+
self.cannot_reborrow_already_uniquely_borrowed(
471467
span,
472468
container_name,
473469
&desc_place,
@@ -482,7 +478,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
482478

483479
(BorrowKind::Mut { .. }, _, lft, BorrowKind::Unique, _, _) => {
484480
first_borrow_desc = "first ";
485-
tcx.cannot_reborrow_already_uniquely_borrowed(
481+
self.cannot_reborrow_already_uniquely_borrowed(
486482
span,
487483
container_name,
488484
&desc_place,
@@ -821,7 +817,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
821817
}
822818
}
823819

824-
let mut err = self.infcx.tcx.path_does_not_live_long_enough(
820+
let mut err = self.path_does_not_live_long_enough(
825821
borrow_span,
826822
&format!("`{}`", name),
827823
);
@@ -912,9 +908,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
912908
let borrow_spans = self.retrieve_borrow_spans(borrow);
913909
let borrow_span = borrow_spans.var_or_use();
914910

915-
let mut err = self.infcx
916-
.tcx
917-
.cannot_borrow_across_destructor(borrow_span);
911+
let mut err = self.cannot_borrow_across_destructor(borrow_span);
918912

919913
let what_was_dropped = match self.describe_place(place) {
920914
Some(name) => format!("`{}`", name.as_str()),
@@ -965,9 +959,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
965959
drop_span, borrow_span
966960
);
967961

968-
let mut err = self.infcx
969-
.tcx
970-
.thread_local_value_does_not_live_long_enough(borrow_span);
962+
let mut err = self.thread_local_value_does_not_live_long_enough(borrow_span);
971963

972964
err.span_label(
973965
borrow_span,
@@ -1011,8 +1003,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10111003
}
10121004
}
10131005

1014-
let tcx = self.infcx.tcx;
1015-
let mut err = tcx.temporary_value_borrowed_for_too_long(proper_span);
1006+
let mut err = self.temporary_value_borrowed_for_too_long(proper_span);
10161007
err.span_label(
10171008
proper_span,
10181009
"creates a temporary which is freed while still in use",
@@ -1055,8 +1046,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10551046
category: ConstraintCategory,
10561047
opt_place_desc: Option<&String>,
10571048
) -> Option<DiagnosticBuilder<'cx>> {
1058-
let tcx = self.infcx.tcx;
1059-
10601049
let return_kind = match category {
10611050
ConstraintCategory::Return => "return",
10621051
ConstraintCategory::Yield => "yield",
@@ -1119,7 +1108,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11191108
}
11201109
};
11211110

1122-
let mut err = tcx.cannot_return_reference_to_local(
1111+
let mut err = self.cannot_return_reference_to_local(
11231112
return_span,
11241113
return_kind,
11251114
reference_desc,
@@ -1144,7 +1133,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11441133
) -> DiagnosticBuilder<'cx> {
11451134
let tcx = self.infcx.tcx;
11461135

1147-
let mut err = tcx.cannot_capture_in_long_lived_closure(
1136+
let mut err = self.cannot_capture_in_long_lived_closure(
11481137
args_span,
11491138
captured_var,
11501139
var_span,
@@ -1203,7 +1192,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12031192
"function"
12041193
};
12051194

1206-
let mut err = tcx.borrowed_data_escapes_closure(escape_span, escapes_from);
1195+
let mut err = borrowck_errors::borrowed_data_escapes_closure(
1196+
tcx,
1197+
escape_span,
1198+
escapes_from,
1199+
);
12071200

12081201
err.span_label(
12091202
upvar_span,
@@ -1345,9 +1338,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13451338
let loan_spans = self.retrieve_borrow_spans(loan);
13461339
let loan_span = loan_spans.args_or_use();
13471340

1348-
let tcx = self.infcx.tcx;
13491341
if loan.kind == BorrowKind::Shallow {
1350-
let mut err = tcx.cannot_mutate_in_match_guard(
1342+
let mut err = self.cannot_mutate_in_match_guard(
13511343
span,
13521344
loan_span,
13531345
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
@@ -1363,7 +1355,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13631355
return;
13641356
}
13651357

1366-
let mut err = tcx.cannot_assign_to_borrowed(
1358+
let mut err = self.cannot_assign_to_borrowed(
13671359
span,
13681360
loan_span,
13691361
&self.describe_place(place).unwrap_or_else(|| "_".to_owned()),
@@ -1427,7 +1419,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14271419
Some(decl) => (self.describe_place(err_place), decl.source_info.span),
14281420
};
14291421

1430-
let mut err = self.infcx.tcx.cannot_reassign_immutable(
1422+
let mut err = self.cannot_reassign_immutable(
14311423
span,
14321424
place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"),
14331425
from_arg,

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use crate::dataflow::MoveDataParamEnv;
4141
use crate::dataflow::{do_dataflow, DebugFormatted};
4242
use crate::dataflow::EverInitializedPlaces;
4343
use crate::dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
44-
use crate::util::borrowck_errors::BorrowckErrors;
4544

4645
use self::borrow_set::{BorrowData, BorrowSet};
4746
use self::flows::Flows;
@@ -423,7 +422,7 @@ fn downgrade_if_error(diag: &mut Diagnostic) {
423422
}
424423

425424
pub struct MirBorrowckCtxt<'cx, 'tcx> {
426-
infcx: &'cx InferCtxt<'cx, 'tcx>,
425+
pub(crate) infcx: &'cx InferCtxt<'cx, 'tcx>,
427426
body: &'cx Body<'tcx>,
428427
mir_def_id: DefId,
429428
move_data: &'cx MoveData<'tcx>,
@@ -1499,8 +1498,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14991498
debug!("check_for_local_borrow({:?})", borrow);
15001499

15011500
if borrow_of_local_data(&borrow.borrowed_place) {
1502-
let err = self.infcx.tcx
1503-
.cannot_borrow_across_generator_yield(
1501+
let err = self.cannot_borrow_across_generator_yield(
15041502
self.retrieve_borrow_spans(borrow).var_or_use(),
15051503
yield_span,
15061504
);

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

+8-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::dataflow::move_paths::{
1212
IllegalMoveOrigin, IllegalMoveOriginKind,
1313
LookupResult, MoveError, MovePathIndex,
1414
};
15-
use crate::util::borrowck_errors::BorrowckErrors;
1615

1716
// Often when desugaring a pattern match we may have many individual moves in
1817
// 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> {
254253
)
255254
}
256255
IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } => {
257-
self.infcx.tcx
258-
.cannot_move_out_of_interior_of_drop(span, ty)
256+
self.cannot_move_out_of_interior_of_drop(span, ty)
259257
}
260258
IllegalMoveOriginKind::InteriorOfSliceOrArray { ty, is_index } =>
261-
self.infcx.tcx.cannot_move_out_of_interior_noncopy(
259+
self.cannot_move_out_of_interior_noncopy(
262260
span, ty, Some(*is_index),
263261
),
264262
},
@@ -293,7 +291,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
293291
)
294292
};
295293

296-
self.infcx.tcx.cannot_move_out_of(span, &description)
294+
self.cannot_move_out_of(span, &description)
297295
}
298296

299297
fn report_cannot_move_from_borrowed_content(
@@ -317,7 +315,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
317315
if let Place::Base(PlaceBase::Local(local)) = *deref_base {
318316
let decl = &self.body.local_decls[local];
319317
if decl.is_ref_for_guard() {
320-
let mut err = self.infcx.tcx.cannot_move_out_of(
318+
let mut err = self.cannot_move_out_of(
321319
span,
322320
&format!("`{}` in pattern guard", decl.name.unwrap()),
323321
);
@@ -331,7 +329,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
331329
debug!("report: ty={:?}", ty);
332330
let mut err = match ty.sty {
333331
ty::Array(..) | ty::Slice(..) =>
334-
self.infcx.tcx.cannot_move_out_of_interior_noncopy(span, ty, None),
332+
self.cannot_move_out_of_interior_noncopy(span, ty, None),
335333
ty::Closure(def_id, closure_substs)
336334
if def_id == self.mir_def_id && upvar_field.is_some()
337335
=> {
@@ -373,7 +371,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
373371
closure_kind_ty, closure_kind, place_description,
374372
);
375373

376-
let mut diag = self.infcx.tcx.cannot_move_out_of(span, &place_description);
374+
let mut diag = self.cannot_move_out_of(span, &place_description);
377375

378376
diag.span_label(upvar_span, "captured outer variable");
379377

@@ -383,13 +381,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
383381
let source = self.borrowed_content_source(deref_base);
384382
match (self.describe_place(move_place), source.describe_for_named_place()) {
385383
(Some(place_desc), Some(source_desc)) => {
386-
self.infcx.tcx.cannot_move_out_of(
384+
self.cannot_move_out_of(
387385
span,
388386
&format!("`{}` which is behind a {}", place_desc, source_desc),
389387
)
390388
}
391389
(_, _) => {
392-
self.infcx.tcx.cannot_move_out_of(
390+
self.cannot_move_out_of(
393391
span,
394392
&source.describe_for_unnamed_place(),
395393
)

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use syntax_pos::symbol::kw;
99

1010
use crate::borrow_check::MirBorrowckCtxt;
1111
use crate::borrow_check::error_reporting::BorrowedContentSource;
12-
use crate::util::borrowck_errors::BorrowckErrors;
1312
use crate::util::collect_writes::FindAssignments;
1413
use crate::util::suggest_ref_mut;
1514
use rustc_errors::Applicability;
@@ -161,13 +160,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
161160

162161
let span = match error_access {
163162
AccessKind::Move => {
164-
err = self.infcx.tcx.cannot_move_out_of(span, &(item_msg + &reason));
163+
err = self.cannot_move_out_of(span, &(item_msg + &reason));
165164
err.span_label(span, "cannot move");
166165
err.buffer(&mut self.errors_buffer);
167166
return;
168167
}
169168
AccessKind::Mutate => {
170-
err = self.infcx.tcx.cannot_assign(span, &(item_msg + &reason));
169+
err = self.cannot_assign(span, &(item_msg + &reason));
171170
act = "assign";
172171
acted_on = "written";
173172
span
@@ -178,7 +177,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
178177

179178
let borrow_spans = self.borrow_spans(span, location);
180179
let borrow_span = borrow_spans.args_or_use();
181-
err = self.infcx.tcx.cannot_borrow_path_as_mutable_because(
180+
err = self.cannot_borrow_path_as_mutable_because(
182181
borrow_span,
183182
&item_msg,
184183
&reason,

0 commit comments

Comments
 (0)