File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -99,14 +99,24 @@ where
99
99
type Output = Either < ( A :: Output , B ) , ( B :: Output , A ) > ;
100
100
101
101
fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
102
+ /// When compiled with `-C opt-level=z`, this function will help the compiler eliminate the `None` branch, where
103
+ /// `Option::unwrap` does not.
104
+ #[ inline( always) ]
105
+ fn unwrap_option < T > ( value : Option < T > ) -> T {
106
+ match value {
107
+ None => unreachable ! ( ) ,
108
+ Some ( value) => value,
109
+ }
110
+ }
111
+
102
112
let ( a, b) = self . inner . as_mut ( ) . expect ( "cannot poll Select twice" ) ;
103
113
104
114
if let Poll :: Ready ( val) = a. poll_unpin ( cx) {
105
- return Poll :: Ready ( Either :: Left ( ( val, self . inner . take ( ) . unwrap ( ) . 1 ) ) ) ;
115
+ return Poll :: Ready ( Either :: Left ( ( val, unwrap_option ( self . inner . take ( ) ) . 1 ) ) ) ;
106
116
}
107
117
108
118
if let Poll :: Ready ( val) = b. poll_unpin ( cx) {
109
- return Poll :: Ready ( Either :: Right ( ( val, self . inner . take ( ) . unwrap ( ) . 0 ) ) ) ;
119
+ return Poll :: Ready ( Either :: Right ( ( val, unwrap_option ( self . inner . take ( ) ) . 0 ) ) ) ;
110
120
}
111
121
112
122
Poll :: Pending
You can’t perform that action at this time.
0 commit comments