File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ //! Tests that panics inside a generator will correctly drop the initial resume argument.
2+
3+ // run-pass
4+
5+ #![ feature( generators, generator_trait) ]
6+
7+ use std:: ops:: Generator ;
8+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
9+ use std:: pin:: Pin ;
10+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
11+
12+ static DROP : AtomicUsize = AtomicUsize :: new ( 0 ) ;
13+
14+ struct Dropper { }
15+
16+ impl Drop for Dropper {
17+ fn drop ( & mut self ) {
18+ DROP . fetch_add ( 1 , Ordering :: SeqCst ) ;
19+ }
20+ }
21+
22+ fn main ( ) {
23+ let mut gen = |_arg| {
24+ if true {
25+ panic ! ( ) ;
26+ }
27+ yield ( ) ;
28+ } ;
29+ let mut gen = Pin :: new ( & mut gen) ;
30+
31+ assert_eq ! ( DROP . load( Ordering :: Acquire ) , 0 ) ;
32+ let res = catch_unwind ( AssertUnwindSafe ( || gen. as_mut ( ) . resume ( Dropper { } ) ) ) ;
33+ assert ! ( res. is_err( ) ) ;
34+ assert_eq ! ( DROP . load( Ordering :: Acquire ) , 1 ) ;
35+ }
Original file line number Diff line number Diff line change 1+ //! Tests that we cannot produce a generator that accepts a resume argument
2+ //! with any lifetime and then stores it across a `yield`.
3+
4+ #![ feature( generators, generator_trait) ]
5+
6+ use std:: ops:: Generator ;
7+
8+ fn test ( a : impl for < ' a > Generator < & ' a mut bool > ) { }
9+
10+ fn main ( ) {
11+ let gen = |arg : & mut bool | {
12+ yield ( ) ;
13+ * arg = true ;
14+ } ;
15+ test ( gen) ;
16+ //~^ ERROR type mismatch in function arguments
17+ }
Original file line number Diff line number Diff line change 1+ error[E0631]: type mismatch in function arguments
2+ --> $DIR/resume-arg-late-bound.rs:15:10
3+ |
4+ LL | fn test(a: impl for<'a> Generator<&'a mut bool>) {}
5+ | ---- ------------------------------- required by this bound in `test`
6+ ...
7+ LL | test(gen);
8+ | ^^^
9+ | |
10+ | expected signature of `for<'a> fn(&'a mut bool) -> _`
11+ | found signature of `fn(&mut bool) -> _`
12+
13+ error: aborting due to previous error
14+
15+ For more information about this error, try `rustc --explain E0631`.
You can’t perform that action at this time.
0 commit comments