@@ -632,10 +632,16 @@ impl<T, E> Result<T, E> {
632
632
/// ```
633
633
#[ inline]
634
634
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
635
- pub fn ok ( self ) -> Option < T > {
635
+ #[ rustc_const_unstable( feature = "const_result_drop" , issue = "92384" ) ]
636
+ pub const fn ok ( self ) -> Option < T >
637
+ where
638
+ E : ~const Drop ,
639
+ {
636
640
match self {
637
641
Ok ( x) => Some ( x) ,
638
- Err ( _) => None ,
642
+ // FIXME: ~const Drop doesn't quite work right yet
643
+ #[ allow( unused_variables) ]
644
+ Err ( x) => None ,
639
645
}
640
646
}
641
647
@@ -657,9 +663,15 @@ impl<T, E> Result<T, E> {
657
663
/// ```
658
664
#[ inline]
659
665
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
660
- pub fn err ( self ) -> Option < E > {
666
+ #[ rustc_const_unstable( feature = "const_result_drop" , issue = "92384" ) ]
667
+ pub const fn err ( self ) -> Option < E >
668
+ where
669
+ T : ~const Drop ,
670
+ {
661
671
match self {
662
- Ok ( _) => None ,
672
+ // FIXME: ~const Drop doesn't quite work right yet
673
+ #[ allow( unused_variables) ]
674
+ Ok ( x) => None ,
663
675
Err ( x) => Some ( x) ,
664
676
}
665
677
}
@@ -1266,10 +1278,18 @@ impl<T, E> Result<T, E> {
1266
1278
/// assert_eq!(x.and(y), Ok("different result type"));
1267
1279
/// ```
1268
1280
#[ inline]
1281
+ #[ rustc_const_unstable( feature = "const_result_drop" , issue = "92384" ) ]
1269
1282
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1270
- pub fn and < U > ( self , res : Result < U , E > ) -> Result < U , E > {
1283
+ pub const fn and < U > ( self , res : Result < U , E > ) -> Result < U , E >
1284
+ where
1285
+ T : ~const Drop ,
1286
+ U : ~const Drop ,
1287
+ E : ~const Drop ,
1288
+ {
1271
1289
match self {
1272
- Ok ( _) => res,
1290
+ // FIXME: ~const Drop doesn't quite work right yet
1291
+ #[ allow( unused_variables) ]
1292
+ Ok ( x) => res,
1273
1293
Err ( e) => Err ( e) ,
1274
1294
}
1275
1295
}
@@ -1343,11 +1363,19 @@ impl<T, E> Result<T, E> {
1343
1363
/// assert_eq!(x.or(y), Ok(2));
1344
1364
/// ```
1345
1365
#[ inline]
1366
+ #[ rustc_const_unstable( feature = "const_result_drop" , issue = "92384" ) ]
1346
1367
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1347
- pub fn or < F > ( self , res : Result < T , F > ) -> Result < T , F > {
1368
+ pub const fn or < F > ( self , res : Result < T , F > ) -> Result < T , F >
1369
+ where
1370
+ T : ~const Drop ,
1371
+ E : ~const Drop ,
1372
+ F : ~const Drop ,
1373
+ {
1348
1374
match self {
1349
1375
Ok ( v) => Ok ( v) ,
1350
- Err ( _) => res,
1376
+ // FIXME: ~const Drop doesn't quite work right yet
1377
+ #[ allow( unused_variables) ]
1378
+ Err ( e) => res,
1351
1379
}
1352
1380
}
1353
1381
@@ -1399,11 +1427,18 @@ impl<T, E> Result<T, E> {
1399
1427
/// assert_eq!(x.unwrap_or(default), default);
1400
1428
/// ```
1401
1429
#[ inline]
1430
+ #[ rustc_const_unstable( feature = "const_result_drop" , issue = "92384" ) ]
1402
1431
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1403
- pub fn unwrap_or ( self , default : T ) -> T {
1432
+ pub const fn unwrap_or ( self , default : T ) -> T
1433
+ where
1434
+ T : ~const Drop ,
1435
+ E : ~const Drop ,
1436
+ {
1404
1437
match self {
1405
1438
Ok ( t) => t,
1406
- Err ( _) => default,
1439
+ // FIXME: ~const Drop doesn't quite work right yet
1440
+ #[ allow( unused_variables) ]
1441
+ Err ( e) => default,
1407
1442
}
1408
1443
}
1409
1444
0 commit comments