about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Sullivan <sully@msully.net>2011-08-19 11:54:46 -0700
committerMichael Sullivan <sully@msully.net>2011-08-19 11:54:46 -0700
commita7e559ee2e04799adfb92b0d8a54758678c170dc (patch)
treee71a77d010d2c1fa8e7dc7768971f5efa17a0f59 /src
parentcc2ebbec92230fa3e377550e42cab4d964bb866d (diff)
downloadrust-a7e559ee2e04799adfb92b0d8a54758678c170dc.tar.gz
rust-a7e559ee2e04799adfb92b0d8a54758678c170dc.zip
Fix polymorphic iterators. Closes #829.
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/trans.rs15
-rw-r--r--src/test/run-pass/polymorphic-iter.rs4
2 files changed, 16 insertions, 3 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index d59a3cf6e34..f587b842986 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -3737,8 +3737,7 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
       ast::expr_call(f, args) {
         let pair =
             create_real_fn_pair(cx, iter_body_llty, lliterbody, llenv.ptr);
-        r = trans_call(cx, f, some::<ValueRef>(cx.build.Load(pair)), args,
-                       seq.id);
+        r = trans_call(cx, f, some(pair), args, seq.id);
         ret rslt(r.bcx, C_nil());
       }
     }
@@ -4626,7 +4625,17 @@ fn trans_args(cx: &@block_ctxt, llenv: ValueRef,
     llargs += lltydescs;
 
     // ... then possibly an lliterbody argument.
-    alt lliterbody { none. { } some(lli) { llargs += ~[lli]; } }
+    alt lliterbody {
+      none. { }
+      some(lli) {
+        let lli = if (ty::type_contains_params(bcx_tcx(cx), retty)) {
+            let body_ty = ty::mk_iter_body_fn(bcx_tcx(cx), retty);
+            let body_llty = type_of_inner(bcx_ccx(cx), cx.sp, body_ty);
+            bcx.build.PointerCast(lli, T_ptr(body_llty))
+        } else { lli };
+        llargs += ~[cx.build.Load(lli)];
+      }
+    }
 
     // ... then explicit args.
 
diff --git a/src/test/run-pass/polymorphic-iter.rs b/src/test/run-pass/polymorphic-iter.rs
new file mode 100644
index 00000000000..46d3705649e
--- /dev/null
+++ b/src/test/run-pass/polymorphic-iter.rs
@@ -0,0 +1,4 @@
+iter iter2<@T>() -> T { }
+fn main() {
+    for each i: int in iter2() { }
+}