Skip to content

librustc: Fix a couple of cases in which unboxed closure typechecking #16637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/test/run-pass/unboxed-closures-zero-args.rs
Original file line number Diff line number Diff line change
@@ -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(());
}