Skip to content

Commit 7fc3d3b

Browse files
committed
moved renamed docs formatted | last-use-in-block.rs
1 parent a10ae04 commit 7fc3d3b

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Regression test for issue #1818
2+
//! last-use analysis in closures should allow moves instead of requiring copies.
3+
//!
4+
//! The original issue was that the compiler incorrectly flagged certain return values
5+
//! in anonymous functions/closures as requiring copies of non-copyable values, when
6+
//! they should have been treated as moves (since they were the last use of the value).
7+
//!
8+
//! See: https://github.com/rust-lang/rust/issues/1818
9+
10+
//@ run-pass
11+
12+
fn apply<T, F>(s: String, mut f: F) -> T
13+
where
14+
F: FnMut(String) -> T
15+
{
16+
fn g<T, F>(s: String, mut f: F) -> T
17+
where
18+
F: FnMut(String) -> T
19+
{
20+
f(s)
21+
}
22+
23+
g(s, |v| {
24+
let r = f(v);
25+
r // This should be a move, not requiring copy
26+
})
27+
}
28+
29+
pub fn main() {
30+
// Actually test the functionality
31+
let result = apply(String::from("test"), |s| s.len());
32+
assert_eq!(result, 4);
33+
}

tests/ui/last-use-in-block.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)