From 4d2ff432e45eedef9d15618b0b9af5378994bc46 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sat, 4 Oct 2014 15:47:16 -0700 Subject: [PATCH] Add regression test for issue #17780 --- src/test/compile-fail/issue-17780.rs | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/test/compile-fail/issue-17780.rs diff --git a/src/test/compile-fail/issue-17780.rs b/src/test/compile-fail/issue-17780.rs new file mode 100644 index 0000000000000..2072b2ee2d2c5 --- /dev/null +++ b/src/test/compile-fail/issue-17780.rs @@ -0,0 +1,50 @@ +// 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, overloaded_calls)] + +fn set(x: &mut uint) { *x = 5; } + +fn main() { + // By-ref captures + { + let mut x = 0u; + let _f = |&:| x = 42; + //~^ ERROR cannot assign to data in a free + // variable from an immutable unboxed closure + + let mut y = 0u; + let _g = |&:| set(&mut y); + //~^ ERROR cannot borrow data mutably in a free + // variable from an immutable unboxed closure + + let mut z = 0u; + let _h = |&mut:| { set(&mut z); |&:| z = 42; }; + //~^ ERROR cannot assign to data in a + // free variable from an immutable unboxed closure + } + // By-value captures + { + let mut x = 0u; + let _f = move |&:| x = 42; + //~^ ERROR cannot assign to data in a free + // variable from an immutable unboxed closure + + let mut y = 0u; + let _g = move |&:| set(&mut y); + //~^ ERROR cannot borrow data mutably in a free + // variable from an immutable unboxed closure + + let mut z = 0u; + let _h = move |&mut:| { set(&mut z); move |&:| z = 42; }; + //~^ ERROR cannot assign to data in a free + // variable from an immutable unboxed closure + } +}