forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of
move
closures -- since they have one fewer deref, w…
…e weren't properly adjusting the closure kind in that case.
- Loading branch information
1 parent
e778ea4
commit a9c3841
Showing
6 changed files
with
167 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/compile-fail/unboxed-closures-infer-fnmut-move-missing-mut.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2015 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that we are able to infer a suitable kind for this closure | ||
// that is just called (`FnMut`). | ||
|
||
fn main() { | ||
let mut counter = 0; | ||
let tick = move || counter += 1; | ||
tick(); //~ ERROR cannot borrow immutable local variable `tick` as mutable | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/compile-fail/unboxed-closures-infer-fnonce-move-call-twice.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2015 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that we are able to infer a suitable kind for this closure | ||
// that is just called (`FnMut`). | ||
|
||
use std::mem; | ||
|
||
fn main() { | ||
let mut counter: Vec<i32> = Vec::new(); | ||
let tick = move || mem::drop(counter); | ||
tick(); | ||
tick(); //~ ERROR use of moved value: `tick` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2015 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that we are able to infer a suitable kind for this `move` | ||
// closure that is just called (`FnMut`). | ||
|
||
fn main() { | ||
let mut counter = 0; | ||
|
||
let v = { | ||
let mut tick = move || { counter += 1; counter }; | ||
tick(); | ||
tick() | ||
}; | ||
|
||
assert_eq!(counter, 0); | ||
assert_eq!(v, 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2015 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(unsafe_destructor)] | ||
|
||
// Test that we are able to infer a suitable kind for this `move` | ||
// closure that is just called (`FnOnce`). | ||
|
||
use std::mem; | ||
|
||
struct DropMe<'a>(&'a mut i32); | ||
|
||
#[unsafe_destructor] | ||
impl<'a> Drop for DropMe<'a> { | ||
fn drop(&mut self) { | ||
*self.0 += 1; | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut counter = 0; | ||
|
||
{ | ||
let drop_me = DropMe(&mut counter); | ||
let tick = move || mem::drop(drop_me); | ||
tick(); | ||
} | ||
|
||
assert_eq!(counter, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters