Skip to content

Commit 85defff

Browse files
Aatchpnkfelix
authored andcommitted
Improve borrowck error when a second move is due to a loop.
(Factoring of aatch CFG code, Part 5.)
1 parent 4bae133 commit 85defff

File tree

1 file changed

+20
-7
lines changed
  • src/librustc_borrowck/borrowck

1 file changed

+20
-7
lines changed

src/librustc_borrowck/borrowck/mod.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,26 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
612612
};
613613
let (suggestion, _) =
614614
move_suggestion(param_env, expr_span, expr_ty, ("moved by default", ""));
615-
self.tcx.sess.span_note(
616-
expr_span,
617-
&format!("`{}` moved here{} because it has type `{}`, which is {}",
618-
ol,
619-
moved_lp_msg,
620-
expr_ty.user_string(self.tcx),
621-
suggestion));
615+
// If the two spans are the same, it's because the expression will be evaluated
616+
// multiple times. Avoid printing the same span and adjust the wording so it makes
617+
// more sense that it's from multiple evalutations.
618+
if expr_span == use_span {
619+
self.tcx.sess.note(
620+
&format!("`{}` was previously moved here{} because it has type `{}`, \
621+
which is {}",
622+
ol,
623+
moved_lp_msg,
624+
expr_ty.user_string(self.tcx),
625+
suggestion));
626+
} else {
627+
self.tcx.sess.span_note(
628+
expr_span,
629+
&format!("`{}` moved here{} because it has type `{}`, which is {}",
630+
ol,
631+
moved_lp_msg,
632+
expr_ty.user_string(self.tcx),
633+
suggestion));
634+
}
622635
}
623636

624637
move_data::MovePat => {

0 commit comments

Comments
 (0)