From 85defffea58139e3e5cc0811e499330fa24267ac Mon Sep 17 00:00:00 2001 From: James Miller Date: Thu, 19 Feb 2015 22:01:09 +0100 Subject: [PATCH] Improve borrowck error when a second move is due to a loop. (Factoring of aatch CFG code, Part 5.) --- src/librustc_borrowck/borrowck/mod.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index dfd98881ace86..2479b6f2ab2bb 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -612,13 +612,26 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { }; let (suggestion, _) = move_suggestion(param_env, expr_span, expr_ty, ("moved by default", "")); - self.tcx.sess.span_note( - expr_span, - &format!("`{}` moved here{} because it has type `{}`, which is {}", - ol, - moved_lp_msg, - expr_ty.user_string(self.tcx), - suggestion)); + // If the two spans are the same, it's because the expression will be evaluated + // multiple times. Avoid printing the same span and adjust the wording so it makes + // more sense that it's from multiple evalutations. + if expr_span == use_span { + self.tcx.sess.note( + &format!("`{}` was previously moved here{} because it has type `{}`, \ + which is {}", + ol, + moved_lp_msg, + expr_ty.user_string(self.tcx), + suggestion)); + } else { + self.tcx.sess.span_note( + expr_span, + &format!("`{}` moved here{} because it has type `{}`, which is {}", + ol, + moved_lp_msg, + expr_ty.user_string(self.tcx), + suggestion)); + } } move_data::MovePat => {