@@ -56,11 +56,11 @@ pub enum GeneratorState<Y, R> {
56
56
/// return "foo"
57
57
/// };
58
58
///
59
- /// match generator.resume() {
59
+ /// match unsafe { generator.resume() } {
60
60
/// GeneratorState::Yielded(1) => {}
61
61
/// _ => panic!("unexpected return from resume"),
62
62
/// }
63
- /// match generator.resume() {
63
+ /// match unsafe { generator.resume() } {
64
64
/// GeneratorState::Complete("foo") => {}
65
65
/// _ => panic!("unexpected return from resume"),
66
66
/// }
@@ -98,6 +98,10 @@ pub trait Generator {
98
98
/// generator will continue executing until it either yields or returns, at
99
99
/// which point this function will return.
100
100
///
101
+ /// The function is unsafe because it can be used on an immovable generator.
102
+ /// After such a call, the immovable generator must not move again, but
103
+ /// this is not enforced by the compiler.
104
+ ///
101
105
/// # Return value
102
106
///
103
107
/// The `GeneratorState` enum returned from this function indicates what
@@ -116,7 +120,7 @@ pub trait Generator {
116
120
/// been returned previously. While generator literals in the language are
117
121
/// guaranteed to panic on resuming after `Complete`, this is not guaranteed
118
122
/// for all implementations of the `Generator` trait.
119
- fn resume ( & mut self ) -> GeneratorState < Self :: Yield , Self :: Return > ;
123
+ unsafe fn resume ( & mut self ) -> GeneratorState < Self :: Yield , Self :: Return > ;
120
124
}
121
125
122
126
#[ unstable( feature = "generator_trait" , issue = "43122" ) ]
@@ -125,7 +129,7 @@ impl<'a, T> Generator for &'a mut T
125
129
{
126
130
type Yield = T :: Yield ;
127
131
type Return = T :: Return ;
128
- fn resume ( & mut self ) -> GeneratorState < Self :: Yield , Self :: Return > {
132
+ unsafe fn resume ( & mut self ) -> GeneratorState < Self :: Yield , Self :: Return > {
129
133
( * * self ) . resume ( )
130
134
}
131
135
}
0 commit comments