Skip to content

Commit b43596b

Browse files
committed
auto merge of #16637 : pcwalton/rust/unboxed-closures-expected-tuple, r=pnkfelix
code wasn't considering the zero-argument case. Closes #16168. r? @pnkfelix
2 parents da796ed + 7f4c5be commit b43596b

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/librustc/middle/typeck/astconv.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,11 @@ pub fn trait_ref_for_unboxed_function<AC:AstConv,
563563
.map(|input| {
564564
ast_ty_to_ty(this, rscope, &*input.ty)
565565
}).collect::<Vec<_>>();
566-
let input_tuple = ty::mk_tup(this.tcx(), input_types);
566+
let input_tuple = if input_types.len() == 0 {
567+
ty::mk_nil()
568+
} else {
569+
ty::mk_tup(this.tcx(), input_types)
570+
};
567571
let output_type = ast_ty_to_ty(this,
568572
rscope,
569573
&*unboxed_function.decl.output);

src/librustc/middle/typeck/check/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,11 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
27152715

27162716
// Tuple up the arguments and insert the resulting function type into
27172717
// the `unboxed_closures` table.
2718-
fn_ty.sig.inputs = vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)];
2718+
fn_ty.sig.inputs = if fn_ty.sig.inputs.len() == 0 {
2719+
vec![ty::mk_nil()]
2720+
} else {
2721+
vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)]
2722+
};
27192723

27202724
let kind = match kind {
27212725
ast::FnUnboxedClosureKind => ty::FnUnboxedClosureKind,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(unboxed_closures)]
12+
13+
fn main() {
14+
let mut zero = |&mut:| {};
15+
zero.call_mut(());
16+
}
17+

0 commit comments

Comments
 (0)