File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -99,14 +99,24 @@ where
9999 type Output = Either < ( A :: Output , B ) , ( B :: Output , A ) > ;
100100
101101 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+
102112 let ( a, b) = self . inner . as_mut ( ) . expect ( "cannot poll Select twice" ) ;
103113
104114 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 ) ) ) ;
106116 }
107117
108118 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 ) ) ) ;
110120 }
111121
112122 Poll :: Pending
You can’t perform that action at this time.
0 commit comments