diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 8b31132f736..f551ff06165 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1209,6 +1209,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // is reserve judgement and then intertwine this // analysis with closure inference. assert_eq!(def_id.krate, ast::LOCAL_CRATE); + + // Unboxed closures shouldn't be + // implicitly copyable + if bound == ty::BoundCopy { + return Ok(ParameterBuiltin); + } + match self.tcx().freevars.borrow().get(&def_id.node) { None => { // No upvars. diff --git a/src/test/compile-fail/unboxed-closer-non-implicit-copyable.rs b/src/test/compile-fail/unboxed-closer-non-implicit-copyable.rs new file mode 100644 index 00000000000..182c632d062 --- /dev/null +++ b/src/test/compile-fail/unboxed-closer-non-implicit-copyable.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures)] + +fn main() { + let f = move|:| (); + f(); + f(); //~ ERROR use of moved value +}