From 127dac4990ec14d47a9f5a78db7d7363b038574f Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Mon, 15 Dec 2014 21:49:49 +0100 Subject: [PATCH] Don't make unboxed closures implicitly copiable The fix just checks if the bound is `Copy` and returns an `Err` if so. Closes: #19817 --- src/librustc/middle/traits/select.rs | 7 +++++++ .../unboxed-closer-non-implicit-copyable.rs | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/compile-fail/unboxed-closer-non-implicit-copyable.rs diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 8b31132f73621..f551ff061654a 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 0000000000000..182c632d06261 --- /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 +}