Skip to content

Commit 9c5e9a5

Browse files
committed
Auto merge of #45167 - pnkfelix:migrate-remaining-ast-diagnostics, r=arielb1
MIR-borrowck: Migrate remaining ast diagnostics This PR migrates all of the remaining diagnostics in `rustc_borrowck` over to `rustc_mir`, exposing them for use by both AST-borrowck and MIR-borrowck. This should hopefully resolve all remaining cases of diagnostic messages emitted from borrowck under `-Z borrowck-mir` without an origin annotation.
2 parents af7de7b + 5b68e1f commit 9c5e9a5

File tree

6 files changed

+622
-530
lines changed

6 files changed

+622
-530
lines changed

src/librustc_borrowck/borrowck/mod.rs

+27-52
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
614614
let partial = moved_lp.depth() > lp.depth();
615615
let msg = if !has_fork && partial { "partially " }
616616
else if has_fork && !has_common { "collaterally "}
617-
else { "" };
618-
let mut err = struct_span_err!(
619-
self.tcx.sess, use_span, E0382,
620-
"{} of {}moved value: `{}`",
621-
verb, msg, nl);
617+
else { "" };
618+
let mut err = self.cannot_act_on_moved_value(use_span,
619+
verb,
620+
msg,
621+
&format!("{}", nl),
622+
Origin::Ast);
622623
let need_note = match lp.ty.sty {
623624
ty::TypeVariants::TyClosure(id, _) => {
624625
let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
@@ -698,10 +699,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
698699
&self,
699700
span: Span,
700701
lp: &LoanPath<'tcx>) {
701-
span_err!(
702-
self.tcx.sess, span, E0383,
703-
"partial reinitialization of uninitialized structure `{}`",
704-
self.loan_path_to_string(lp));
702+
self.cannot_partially_reinit_an_uninit_struct(span,
703+
&self.loan_path_to_string(lp),
704+
Origin::Ast)
705+
.emit();
705706
}
706707

707708
pub fn report_reassigned_immutable_variable(&self,
@@ -776,8 +777,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
776777
db
777778
}
778779
BorrowViolation(euv::ClosureCapture(_)) => {
779-
struct_span_err!(self.tcx.sess, error_span, E0595,
780-
"closure cannot assign to {}", descr)
780+
self.closure_cannot_assign_to_borrowed(error_span, &descr, Origin::Ast)
781781
}
782782
BorrowViolation(euv::OverloadedOperator) |
783783
BorrowViolation(euv::AddrOf) |
@@ -786,8 +786,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
786786
BorrowViolation(euv::AutoUnsafe) |
787787
BorrowViolation(euv::ForLoop) |
788788
BorrowViolation(euv::MatchDiscriminant) => {
789-
struct_span_err!(self.tcx.sess, error_span, E0596,
790-
"cannot borrow {} as mutable", descr)
789+
self.cannot_borrow_path_as_mutable(error_span, &descr, Origin::Ast)
791790
}
792791
BorrowViolation(euv::ClosureInvocation) => {
793792
span_bug!(err.span,
@@ -869,21 +868,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
869868

870869
if let Some((yield_span, _)) = maybe_borrow_across_yield {
871870
debug!("err_out_of_scope: opt_yield_span = {:?}", yield_span);
872-
struct_span_err!(self.tcx.sess,
873-
error_span,
874-
E0626,
875-
"borrow may still be in use when generator yields")
876-
.span_label(yield_span, "possible yield occurs here")
871+
self.cannot_borrow_across_generator_yield(error_span, yield_span, Origin::Ast)
877872
.emit();
878873
return;
879874
}
880875

881-
let mut db = struct_span_err!(self.tcx.sess,
882-
error_span,
883-
E0597,
884-
"{} does not live long enough",
885-
msg);
886-
876+
let mut db = self.path_does_not_live_long_enough(error_span, &msg, Origin::Ast);
887877
let (value_kind, value_msg) = match err.cmt.cat {
888878
mc::Categorization::Rvalue(..) =>
889879
("temporary value", "temporary value created here"),
@@ -992,11 +982,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
992982
}
993983
err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {
994984
let descr = self.cmt_to_path_or_string(&err.cmt);
995-
let mut db = struct_span_err!(self.tcx.sess, error_span, E0598,
996-
"lifetime of {} is too short to guarantee \
997-
its contents can be safely reborrowed",
998-
descr);
999-
985+
let mut db = self.lifetime_too_short_for_reborrow(error_span, &descr, Origin::Ast);
1000986
let descr = match opt_loan_path(&err.cmt) {
1001987
Some(lp) => {
1002988
format!("`{}`", self.loan_path_to_string(&lp))
@@ -1068,12 +1054,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10681054
let blame = cmt.immutability_blame();
10691055
let mut err = match blame {
10701056
Some(ImmutabilityBlame::ClosureEnv(id)) => {
1071-
let mut err = struct_span_err!(
1072-
self.tcx.sess, span, E0387,
1073-
"{} in a captured outer variable in an `Fn` closure", prefix);
1074-
10751057
// FIXME: the distinction between these 2 messages looks wrong.
1076-
let help = if let BorrowViolation(euv::ClosureCapture(_)) = kind {
1058+
let help_msg = if let BorrowViolation(euv::ClosureCapture(_)) = kind {
10771059
// The aliasability violation with closure captures can
10781060
// happen for nested closures, so we know the enclosing
10791061
// closure incorrectly accepts an `Fn` while it needs to
@@ -1084,15 +1066,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10841066
"consider changing this closure to take self by mutable reference"
10851067
};
10861068
let node_id = self.tcx.hir.def_index_to_node_id(id);
1087-
err.span_help(self.tcx.hir.span(node_id), help);
1088-
err
1069+
let help_span = self.tcx.hir.span(node_id);
1070+
self.cannot_act_on_capture_in_sharable_fn(span,
1071+
prefix,
1072+
(help_span, help_msg),
1073+
Origin::Ast)
10891074
}
10901075
_ => {
1091-
let mut err = struct_span_err!(
1092-
self.tcx.sess, span, E0389,
1093-
"{} in a `&` reference", prefix);
1094-
err.span_label(span, "assignment into an immutable reference");
1095-
err
1076+
self.cannot_assign_into_immutable_reference(span, prefix,
1077+
Origin::Ast)
10961078
}
10971079
};
10981080
self.note_immutability_blame(&mut err, blame);
@@ -1244,17 +1226,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12441226
Err(_) => format!("move |<args>| <body>")
12451227
};
12461228

1247-
struct_span_err!(self.tcx.sess, err.span, E0373,
1248-
"closure may outlive the current function, \
1249-
but it borrows {}, \
1250-
which is owned by the current function",
1251-
cmt_path_or_string)
1252-
.span_label(capture_span,
1253-
format!("{} is borrowed here",
1254-
cmt_path_or_string))
1255-
.span_label(err.span,
1256-
format!("may outlive borrowed value {}",
1257-
cmt_path_or_string))
1229+
self.cannot_capture_in_long_lived_closure(err.span,
1230+
&cmt_path_or_string,
1231+
capture_span,
1232+
Origin::Ast)
12581233
.span_suggestion(err.span,
12591234
&format!("to force the closure to take ownership of {} \
12601235
(and any other referenced variables), \

0 commit comments

Comments
 (0)