]> git.lizzy.rs Git - rust.git/commitdiff
Improve check to consider how value is used.
authorDavid Wood <david@davidtw.co>
Tue, 16 Oct 2018 17:37:01 +0000 (19:37 +0200)
committerDavid Wood <david@davidtw.co>
Thu, 18 Oct 2018 16:21:15 +0000 (18:21 +0200)
src/librustc_mir/borrow_check/error_reporting.rs
src/test/ui/issues/issue-12127.nll.stderr [deleted file]

index 3903506068ed702bbcf136ea1946d5341187e37d..baf9e032270a684e9af3cc3d9471d58b3e897a4f 100644 (file)
@@ -1133,32 +1133,25 @@ pub(super) fn add_closure_invoked_twice_with_moved_variable_suggestion(
                      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 (file)
index 51dd2e7..0000000
+++ /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<isize>]`, which does not implement the `Copy` trait
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0382`.