File tree Expand file tree Collapse file tree 2 files changed +32
-17
lines changed Expand file tree Collapse file tree 2 files changed +32
-17
lines changed Original file line number Diff line number Diff line change 1+ //! Regression test for issue #1399
2+ //!
3+ //! This test ensures that the compiler's last-use analysis correctly handles variables
4+ //! that are captured by closures (upvars). The original issue was that the analyzer
5+ //! would incorrectly optimize variable usage as "last use" and perform moves, even when
6+ //! the variable was later needed by a closure that captured it.
7+ //!
8+ //! See: https://github.com/rust-lang/rust/issues/1399
9+
10+ //@ run-pass
11+
12+ struct A {
13+ _a : Box < isize >
14+ }
15+
16+ fn foo ( ) -> Box < dyn FnMut ( ) -> isize + ' static > {
17+ let k: Box < _ > = Box :: new ( 22 ) ;
18+
19+ // This use of k.clone() should not be treated as a "last use"
20+ // even though the closure below doesn't actually capture k
21+ let _u = A { _a : k. clone ( ) } ;
22+
23+ // The closure doesn't actually use k, but the analyzer needs to handle
24+ // the potential capture scenario correctly
25+ let result = || 22 ;
26+
27+ Box :: new ( result)
28+ }
29+
30+ pub fn main ( ) {
31+ assert_eq ! ( foo( ) ( ) , 22 ) ;
32+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments