Skip to content

Commit 127dac4

Browse files
committed
Don't make unboxed closures implicitly copiable
The fix just checks if the bound is `Copy` and returns an `Err` if so. Closes: #19817
1 parent 126db54 commit 127dac4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc/middle/traits/select.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12091209
// is reserve judgement and then intertwine this
12101210
// analysis with closure inference.
12111211
assert_eq!(def_id.krate, ast::LOCAL_CRATE);
1212+
1213+
// Unboxed closures shouldn't be
1214+
// implicitly copyable
1215+
if bound == ty::BoundCopy {
1216+
return Ok(ParameterBuiltin);
1217+
}
1218+
12121219
match self.tcx().freevars.borrow().get(&def_id.node) {
12131220
None => {
12141221
// No upvars.
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 f = move|:| ();
15+
f();
16+
f(); //~ ERROR use of moved value
17+
}

0 commit comments

Comments
 (0)