]> git.lizzy.rs Git - rust.git/commitdiff
Don't allow bind to produce bare functions
authorBrian Anderson <banderson@mozilla.com>
Mon, 10 Oct 2011 20:50:13 +0000 (13:50 -0700)
committerBrian Anderson <banderson@mozilla.com>
Tue, 11 Oct 2011 17:51:10 +0000 (10:51 -0700)
Issue #1022

src/comp/middle/typeck.rs
src/test/compile-fail/fn-bare-bind.rs [new file with mode: 0644]

index 324c9e16b17a7be0e4ea3dd1619e8f4ee283c566..94ac0cf3ed187824a2d39fcd08336d453bace4cc 100644 (file)
@@ -2116,7 +2116,18 @@ fn check_binop_type_compat(fcx: @fn_ctxt, span: span, ty: ty::t,
             }
             i += 1u;
         }
-        let ft = ty::mk_fn(tcx, proto, out_args, rt, cf, constrs);
+
+        // Determine what fn prototype results from binding
+        fn lower_bound_proto(proto: ast::proto) -> ast::proto {
+            // FIXME: This is right for bare fns, possibly not others
+            alt proto {
+              ast::proto_bare. { ast::proto_fn }
+              _ { proto }
+            }
+        }
+
+        let ft = ty::mk_fn(tcx, lower_bound_proto(proto),
+                           out_args, rt, cf, constrs);
         write::ty_only_fixup(fcx, id, ft);
       }
       ast::expr_call(f, args) {
diff --git a/src/test/compile-fail/fn-bare-bind.rs b/src/test/compile-fail/fn-bare-bind.rs
new file mode 100644 (file)
index 0000000..c8f4960
--- /dev/null
@@ -0,0 +1,9 @@
+// error-pattern:mismatched types: expected fn#() but found fn()
+
+fn# f() {
+}
+
+fn main() {
+    // Can't produce a bare function by binding
+    let g: fn#() = bind f();
+}
\ No newline at end of file