Skip to content

Commit 7f4c5be

Browse files
committed
librustc: Fix a couple of cases in which unboxed closure typechecking
code wasn't considering the zero-argument case. Closes #16168.
1 parent 43f040d commit 7f4c5be

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
@@ -2678,7 +2678,11 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
26782678

26792679
// Tuple up the arguments and insert the resulting function type into
26802680
// the `unboxed_closures` table.
2681-
fn_ty.sig.inputs = vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)];
2681+
fn_ty.sig.inputs = if fn_ty.sig.inputs.len() == 0 {
2682+
vec![ty::mk_nil()]
2683+
} else {
2684+
vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)]
2685+
};
26822686

26832687
let kind = match kind {
26842688
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)