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,
+ ),
+ );
+ }
}
}
}
+++ /dev/null
-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<isize>]`, which does not implement the `Copy` trait
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0382`.