Skip to content

Commit 93c85eb

Browse files
committed
auto merge of #18730 : bkoropoff/rust/issue-18652, r=eddyb
`FnOnce` environments that fit within an `int` are passed to the closure by value. For some reason there was an assert that this would only happen if there were 1 or 0 free variables, but it can also happen if there are multiple variables that happen to fit. Closes #18652
2 parents f0ca717 + 2c956d0 commit 93c85eb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/librustc/middle/trans/closure.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
323323
self_type,
324324
"unboxed_closure_env");
325325
store_ty(bcx, bcx.fcx.llenv.unwrap(), datum.val, self_type);
326-
assert!(freevars.len() <= 1);
327326
datum.val
328327
} else {
329328
bcx.fcx.llenv.unwrap()

src/test/run-pass/issue-18652.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// Tests multiple free variables being passed by value into an unboxed
12+
// once closure as an optimization by trans. This used to hit an
13+
// incorrect assert.
14+
15+
#![feature(unboxed_closures, overloaded_calls)]
16+
17+
fn main() {
18+
let x = 2u8;
19+
let y = 3u8;
20+
assert_eq!((move |:| x + y)(), 5);
21+
}

0 commit comments

Comments
 (0)