diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-08-20 13:37:00 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-08-20 14:14:55 -0700 |
| commit | 7f4c5be81ad06ec51ab62de981ea2c2d4b9c0218 (patch) | |
| tree | 7b5c952aadb271f1278914a8070eb5b6c29c48c2 | |
| parent | 43f040dac892b8685ae7a89911910980c3f8531f (diff) | |
librustc: Fix a couple of cases in which unboxed closure typechecking
code wasn't considering the zero-argument case. Closes #16168.
| -rw-r--r-- | src/librustc/middle/typeck/astconv.rs | 6 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/mod.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/unboxed-closures-zero-args.rs | 17 |
3 files changed, 27 insertions, 2 deletions
diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index add31ed87ce..d646dc9c082 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -563,7 +563,11 @@ pub fn trait_ref_for_unboxed_function<AC:AstConv, .map(|input| { ast_ty_to_ty(this, rscope, &*input.ty) }).collect::<Vec<_>>(); - let input_tuple = ty::mk_tup(this.tcx(), input_types); + let input_tuple = if input_types.len() == 0 { + ty::mk_nil() + } else { + ty::mk_tup(this.tcx(), input_types) + }; let output_type = ast_ty_to_ty(this, rscope, &*unboxed_function.decl.output); diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 1cec680ff2c..6d9054c46ce 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2678,7 +2678,11 @@ fn check_expr_with_unifier(fcx: &FnCtxt, // Tuple up the arguments and insert the resulting function type into // the `unboxed_closures` table. - fn_ty.sig.inputs = vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)]; + fn_ty.sig.inputs = if fn_ty.sig.inputs.len() == 0 { + vec![ty::mk_nil()] + } else { + vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)] + }; let kind = match kind { ast::FnUnboxedClosureKind => ty::FnUnboxedClosureKind, diff --git a/src/test/run-pass/unboxed-closures-zero-args.rs b/src/test/run-pass/unboxed-closures-zero-args.rs new file mode 100644 index 00000000000..6d6d81fd0ef --- /dev/null +++ b/src/test/run-pass/unboxed-closures-zero-args.rs @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +#![feature(unboxed_closures)] + +fn main() { + let mut zero = |&mut:| {}; + zero.call_mut(()); +} + |
