@@ -71,7 +71,6 @@ use cmp::PartialOrd;
71
71
use fmt;
72
72
use marker:: { Sized , Unsize } ;
73
73
use result:: Result :: { self , Ok , Err } ;
74
- use option:: Option :: { self , Some , None } ;
75
74
76
75
/// The `Drop` trait is used to run some code when a value goes out of scope.
77
76
/// This is sometimes called a 'destructor'.
@@ -2198,75 +2197,23 @@ impl<U, V> Carrier for Result<U, V> {
2198
2197
}
2199
2198
}
2200
2199
2201
- #[ unstable( feature = "question_mark_carrier" , issue = "31436" ) ]
2202
- impl < U > Carrier for Option < U > {
2203
- type Success = U ;
2204
- type Error = ( ) ;
2205
-
2206
- fn from_success ( u : U ) -> Option < U > {
2207
- Some ( u)
2208
- }
2200
+ struct _DummyErrorType ;
2209
2201
2210
- fn from_error ( _: ( ) ) -> Option < U > {
2211
- None
2212
- }
2213
-
2214
- fn translate < T > ( self ) -> T
2215
- where T : Carrier < Success =U , Error =( ) >
2216
- {
2217
- match self {
2218
- Some ( u) => T :: from_success ( u) ,
2219
- None => T :: from_error ( ( ) ) ,
2220
- }
2221
- }
2222
- }
2223
-
2224
- // Implementing Carrier for bools means it's easy to write short-circuiting
2225
- // functions. E.g.,
2226
- // ```
2227
- // fn foo() -> bool {
2228
- // if !(f() || g()) {
2229
- // return false;
2230
- // }
2231
- //
2232
- // some_computation();
2233
- // if h() {
2234
- // return false;
2235
- // }
2236
- //
2237
- // more_computation();
2238
- // i()
2239
- // }
2240
- // ```
2241
- // becomes
2242
- // ```
2243
- // fn foo() -> bool {
2244
- // (f() || g())?;
2245
- // some_computation();
2246
- // (!h())?;
2247
- // more_computation();
2248
- // i()
2249
- // }
2250
- // ```
2251
- #[ unstable( feature = "question_mark_carrier" , issue = "31436" ) ]
2252
- impl Carrier for bool {
2202
+ impl Carrier for _DummyErrorType {
2253
2203
type Success = ( ) ;
2254
2204
type Error = ( ) ;
2255
2205
2256
- fn from_success ( _: ( ) ) -> bool {
2257
- true
2206
+ fn from_success ( _: ( ) ) -> _DummyErrorType {
2207
+ _DummyErrorType
2258
2208
}
2259
2209
2260
- fn from_error ( _: ( ) ) -> bool {
2261
- false
2210
+ fn from_error ( _: ( ) ) -> _DummyErrorType {
2211
+ _DummyErrorType
2262
2212
}
2263
2213
2264
2214
fn translate < T > ( self ) -> T
2265
2215
where T : Carrier < Success =( ) , Error =( ) >
2266
2216
{
2267
- match self {
2268
- true => T :: from_success ( ( ) ) ,
2269
- false => T :: from_error ( ( ) ) ,
2270
- }
2217
+ T :: from_success ( ( ) )
2271
2218
}
2272
2219
}
0 commit comments