about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEdward Wang <edward.yu.wang@gmail.com>2015-01-24 03:13:26 +0800
committerEdward Wang <edward.yu.wang@gmail.com>2015-01-24 03:13:26 +0800
commit296777e50a6e1c3fe2dfaadbd25b01cc3071cf7c (patch)
treede6b426de9f1e1a25f08243a21a5448399e5b875
parentaedcbb9d82ccd7ead4b075ff55a99e363be94174 (diff)
downloadrust-296777e50a6e1c3fe2dfaadbd25b01cc3071cf7c.tar.gz
rust-296777e50a6e1c3fe2dfaadbd25b01cc3071cf7c.zip
Resolve type vars when inferring borrow kinds for upvars
As part of #20432, upvar checking is now moved out of regionck to its
own pass and before regionck. But regionck has some type resolution of
its own. Without them, now separated upvar checking may be tripped over
by residue `ty_infer`.

Closes #21306
-rw-r--r--src/librustc_typeck/check/mod.rs3
-rw-r--r--src/librustc_typeck/check/upvar.rs7
-rw-r--r--src/test/run-pass/issue-21306.rs17
3 files changed, 20 insertions, 7 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 5f8ae09b5bd..584b6361f35 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -1635,6 +1635,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     {
         let raw_ty = self.expr_ty(expr);
         let raw_ty = self.infcx().shallow_resolve(raw_ty);
+        let resolve_ty = |&: ty: Ty<'tcx>| self.infcx().resolve_type_vars_if_possible(&ty);
         ty::adjust_ty(self.tcx(),
                       expr.span,
                       expr.id,
@@ -1642,7 +1643,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                       adjustment,
                       |method_call| self.inh.method_map.borrow()
                                                        .get(&method_call)
-                                                       .map(|method| method.ty))
+                                                       .map(|method| resolve_ty(method.ty)))
     }
 
     pub fn node_ty(&self, id: ast::NodeId) -> Ty<'tcx> {
diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs
index ec44d765a8e..7fc0a83e34a 100644
--- a/src/librustc_typeck/check/upvar.rs
+++ b/src/librustc_typeck/check/upvar.rs
@@ -121,13 +121,8 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
                      capture_clause: ast::CaptureClause,
                      _body: &ast::Block)
     {
-        let is_old_skool_closure = match self.fcx.expr_ty(expr).sty {
-            _ => false,
-        };
-
         match capture_clause {
-            ast::CaptureByValue if !is_old_skool_closure => {
-            }
+            ast::CaptureByValue => {}
             _ => {
                 ty::with_freevars(self.tcx(), expr.id, |freevars| {
                     for freevar in freevars.iter() {
diff --git a/src/test/run-pass/issue-21306.rs b/src/test/run-pass/issue-21306.rs
new file mode 100644
index 00000000000..c75abd88963
--- /dev/null
+++ b/src/test/run-pass/issue-21306.rs
@@ -0,0 +1,17 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::sync::Arc;
+
+fn main() {
+    let x = 5us;
+    let command = Arc::new(Box::new(|&:| { x*2 }));
+    assert_eq!(command(), 10);
+}