Skip to content

Commit b000803

Browse files
committed
borrowck some amount of diag migration
1 parent ff40f2e commit b000803

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1086
-322
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use crate::nll::ToRegionVid;
24
use crate::path_utils::allow_two_phase_borrow;
35
use crate::place_ext::PlaceExt;

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ use rustc_errors::{
44
use rustc_middle::ty::{self, Ty, TyCtxt};
55
use rustc_span::Span;
66

7+
use crate::session_diagnostics::{
8+
AssignBorrowErr, BorrowAcrossDestructor, BorrowAcrossGeneratorYield, ClosureConstructLabel,
9+
InteriorDropMoveErr, MoveBorrowedErr, PathShortLive, TwoClosuresUniquelyBorrowErr,
10+
UseMutBorrowErr,
11+
};
12+
713
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
814
pub(crate) fn cannot_move_when_borrowed(
915
&self,
1016
span: Span,
1117
desc: &str,
1218
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
13-
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
19+
self.infcx.tcx.sess.create_err(MoveBorrowedErr { desc, span })
1420
}
1521

1622
pub(crate) fn cannot_use_when_mutably_borrowed(
@@ -20,17 +26,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
2026
borrow_span: Span,
2127
borrow_desc: &str,
2228
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
23-
let mut err = struct_span_err!(
24-
self,
25-
span,
26-
E0503,
27-
"cannot use {} because it was mutably borrowed",
28-
desc,
29-
);
30-
31-
err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_desc));
32-
err.span_label(span, format!("use of borrowed {}", borrow_desc));
33-
err
29+
self.infcx.tcx.sess.create_err(UseMutBorrowErr { desc, borrow_desc, span, borrow_span })
3430
}
3531

3632
pub(crate) fn cannot_mutably_borrow_multiply(
@@ -90,26 +86,22 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
9086
old_loan_span: Span,
9187
old_load_end_span: Option<Span>,
9288
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
93-
let mut err = struct_span_err!(
94-
self,
95-
new_loan_span,
96-
E0524,
97-
"two closures require unique access to {} at the same time",
98-
desc,
99-
);
89+
let case: ClosureConstructLabel;
90+
let diff_span: Option<Span>;
10091
if old_loan_span == new_loan_span {
101-
err.span_label(
102-
old_loan_span,
103-
"closures are constructed here in different iterations of loop",
104-
);
92+
case = ClosureConstructLabel::Both { old_loan_span };
93+
diff_span = None;
10594
} else {
106-
err.span_label(old_loan_span, "first closure is constructed here");
107-
err.span_label(new_loan_span, "second closure is constructed here");
95+
case = ClosureConstructLabel::First { old_loan_span };
96+
diff_span = Some(new_loan_span);
10897
}
109-
if let Some(old_load_end_span) = old_load_end_span {
110-
err.span_label(old_load_end_span, "borrow from first closure ends here");
111-
}
112-
err
98+
self.infcx.tcx.sess.create_err(TwoClosuresUniquelyBorrowErr {
99+
desc,
100+
case,
101+
new_loan_span,
102+
old_load_end_span,
103+
diff_span,
104+
})
113105
}
114106

115107
pub(crate) fn cannot_uniquely_borrow_by_one_closure(
@@ -233,17 +225,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
233225
borrow_span: Span,
234226
desc: &str,
235227
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
236-
let mut err = struct_span_err!(
237-
self,
238-
span,
239-
E0506,
240-
"cannot assign to {} because it is borrowed",
241-
desc,
242-
);
243-
244-
err.span_label(borrow_span, format!("borrow of {} occurs here", desc));
245-
err.span_label(span, format!("assignment to borrowed {} occurs here", desc));
246-
err
228+
self.infcx.tcx.sess.create_err(AssignBorrowErr { desc, span, borrow_span })
247229
}
248230

249231
pub(crate) fn cannot_reassign_immutable(
@@ -303,15 +285,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
303285
move_from_span: Span,
304286
container_ty: Ty<'_>,
305287
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
306-
let mut err = struct_span_err!(
307-
self,
308-
move_from_span,
309-
E0509,
310-
"cannot move out of type `{}`, which implements the `Drop` trait",
311-
container_ty,
312-
);
313-
err.span_label(move_from_span, "cannot move out of here");
314-
err
288+
self.infcx.tcx.sess.create_err(InteriorDropMoveErr { container_ty, move_from_span })
315289
}
316290

317291
pub(crate) fn cannot_act_on_moved_value(
@@ -370,34 +344,22 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
370344
span: Span,
371345
yield_span: Span,
372346
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
373-
let mut err = struct_span_err!(
374-
self,
375-
span,
376-
E0626,
377-
"borrow may still be in use when generator yields",
378-
);
379-
err.span_label(yield_span, "possible yield occurs here");
380-
err
347+
self.infcx.tcx.sess.create_err(BorrowAcrossGeneratorYield { span, yield_span })
381348
}
382349

383350
pub(crate) fn cannot_borrow_across_destructor(
384351
&self,
385352
borrow_span: Span,
386353
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
387-
struct_span_err!(
388-
self,
389-
borrow_span,
390-
E0713,
391-
"borrow may still be in use when destructor runs",
392-
)
354+
self.infcx.tcx.sess.create_err(BorrowAcrossDestructor { borrow_span })
393355
}
394356

395357
pub(crate) fn path_does_not_live_long_enough(
396358
&self,
397359
span: Span,
398360
path: &str,
399361
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
400-
struct_span_err!(self, span, E0597, "{} does not live long enough", path,)
362+
self.infcx.tcx.sess.create_err(PathShortLive { path, span })
401363
}
402364

403365
pub(crate) fn cannot_return_reference_to_local(

compiler/rustc_borrowck/src/constraint_generation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use rustc_infer::infer::InferCtxt;
24
use rustc_middle::mir::visit::TyContext;
35
use rustc_middle::mir::visit::Visitor;

compiler/rustc_borrowck/src/constraints/graph.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use rustc_data_structures::graph;
25
use rustc_index::vec::IndexVec;
36
use rustc_middle::mir::ConstraintCategory;

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use rustc_data_structures::graph::scc::Sccs;
25
use rustc_index::vec::IndexVec;
36
use rustc_middle::mir::ConstraintCategory;

compiler/rustc_borrowck/src/consumers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
//! This file provides API for compiler consumers.
24
35
use rustc_hir::def_id::LocalDefId;

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use rustc_data_structures::fx::FxHashMap;
24
use rustc_index::bit_set::BitSet;
35
use rustc_middle::mir::{self, BasicBlock, Body, Location, Place};

compiler/rustc_borrowck/src/def_use.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
use rustc_middle::mir::visit::{
24
MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext,
35
};

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
25
use rustc_infer::infer::canonical::Canonical;
36
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
180180
let move_spans = self.move_spans(moved_place.as_ref(), move_out.source);
181181
let move_span = move_spans.args_or_use();
182182

183-
let move_msg = if move_spans.for_closure() { " into closure" } else { "" };
183+
let move_msg = if move_spans.for_closure() { "InClosure" } else { "" };
184184

185185
let loop_message = if location == move_out.source || move_site.traversed_back_edge {
186-
", in previous iteration of loop"
186+
"InLoop"
187187
} else {
188188
""
189189
};

0 commit comments

Comments
 (0)