diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 3903506068ed7..baf9e032270a6 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -1133,32 +1133,25 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { closure, ); - if let ty::TyKind::Closure(did, substs) = self.mir.local_decls[closure].ty.sty { - let upvar_tys = substs.upvar_tys(did, self.infcx.tcx); + if let ty::TyKind::Closure(did, _substs) = self.mir.local_decls[closure].ty.sty { let node_id = match self.infcx.tcx.hir.as_local_node_id(did) { Some(node_id) => node_id, _ => return, }; - - self.infcx.tcx.with_freevars(node_id, |freevars| { - for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) { - debug!( - "add_closure_invoked_twice_with_moved_variable_suggestion: \ - freevar={:?} upvar_ty={:?}", - freevar, upvar_ty, - ); - if !upvar_ty.is_region_ptr() { - diag.span_note( - freevar.span, - &format!( - "closure cannot be invoked more than once because it \ - moves the variable `{}` out of its environment", - self.infcx.tcx.hir.name(freevar.var_id()), - ), - ); - } - } - }); + let hir_id = self.infcx.tcx.hir.node_to_hir_id(node_id); + + if let Some(( + span, name + )) = self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) { + diag.span_note( + *span, + &format!( + "closure cannot be invoked more than once because it \ + moves the variable `{}` out of its environment", + name, + ), + ); + } } } } diff --git a/src/test/ui/issues/issue-12127.nll.stderr b/src/test/ui/issues/issue-12127.nll.stderr deleted file mode 100644 index 51dd2e72832b6..0000000000000 --- a/src/test/ui/issues/issue-12127.nll.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0382]: use of moved value: `f` - --> $DIR/issue-12127.rs:21:9 - | -LL | f(); - | - value moved here -LL | f(); - | ^ value used here after move - | -note: closure cannot be invoked more than once because it moves the variable `x` out of its environment - --> $DIR/issue-12127.rs:18:39 - | -LL | let f = to_fn_once(move|| do_it(&*x)); - | ^ - = note: move occurs because `f` has type `[closure@$DIR/issue-12127.rs:18:24: 18:41 x:std::boxed::Box]`, which does not implement the `Copy` trait - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0382`.