diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index d8a3cf9947024..56b87feb82b2c 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -203,20 +203,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { Some(ref name) => format!("`{}`", name), None => "value".to_owned(), }; - let mut note = true; - for decl in &self.mir.local_decls { - if decl.ty == ty && decl.name.map(|x| x.to_string()) == opt_name { - err.span_label( - decl.source_info.span, - format!( - "move occurs because {} has type `{}`, \ - which does not implement the `Copy` trait", - note_msg, ty, - )); - note = false; - break; - } - } if let ty::TyKind::Param(param_ty) = ty.sty { let tcx = self.infcx.tcx; let generics = tcx.generics_of(self.mir_def_id); @@ -228,7 +214,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { ); } } - if note { + if let Place::Local(local) = place { + let decl = &self.mir.local_decls[*local]; + err.span_label( + decl.source_info.span, + format!( + "move occurs because {} has type `{}`, \ + which does not implement the `Copy` trait", + note_msg, ty, + )); + } else { err.note(&format!( "move occurs because {} has type `{}`, \ which does not implement the `Copy` trait", diff --git a/src/test/ui/borrowck/issue-41962.stderr b/src/test/ui/borrowck/issue-41962.stderr index 3c0071f6b3745..fd4d318b5ddf1 100644 --- a/src/test/ui/borrowck/issue-41962.stderr +++ b/src/test/ui/borrowck/issue-41962.stderr @@ -19,13 +19,10 @@ LL | if let Some(thing) = maybe { error[E0382]: use of moved value (Mir) --> $DIR/issue-41962.rs:7:21 | -LL | let maybe = Some(vec![true, true]); - | ---------------- move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait -... LL | if let Some(thing) = maybe { | ^^^^^ value moved here, in previous iteration of loop | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = note: move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait error: aborting due to 3 previous errors