File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
src/test/run-pass/generator Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ // Regression test for incorrect DropAndReplace behavior introduced in #60840
2+ // and fixed in #61373. When combined with the optimization implemented in
3+ // #60187, this produced incorrect code for generators when a saved local was
4+ // re-assigned.
5+
6+ #![ feature( generators, generator_trait) ]
7+
8+ use std:: ops:: { Generator , GeneratorState } ;
9+ use std:: pin:: Pin ;
10+
11+ #[ derive( Debug , PartialEq ) ]
12+ struct Foo ( i32 ) ;
13+
14+ impl Drop for Foo {
15+ fn drop ( & mut self ) { }
16+ }
17+
18+ fn main ( ) {
19+ let mut a = || {
20+ let mut x = Foo ( 4 ) ;
21+ yield ;
22+ assert_eq ! ( x. 0 , 4 ) ;
23+
24+ // At one point this tricked our dataflow analysis into thinking `x` was
25+ // StorageDead after the assignment.
26+ x = Foo ( 5 ) ;
27+ assert_eq ! ( x. 0 , 5 ) ;
28+
29+ {
30+ let y = Foo ( 6 ) ;
31+ yield ;
32+ assert_eq ! ( y. 0 , 6 ) ;
33+ }
34+
35+ assert_eq ! ( x. 0 , 5 ) ;
36+ } ;
37+
38+ loop {
39+ match Pin :: new ( & mut a) . resume ( ) {
40+ GeneratorState :: Complete ( ( ) ) => break ,
41+ _ => ( ) ,
42+ }
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments