536
536
use crate :: iter:: { self , FusedIterator , TrustedLen } ;
537
537
use crate :: marker:: Destruct ;
538
538
use crate :: ops:: { self , ControlFlow , Deref , DerefMut } ;
539
- use crate :: panic:: const_panic;
540
539
use crate :: { convert, fmt, hint} ;
541
540
542
541
/// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]).
@@ -609,8 +608,9 @@ impl<T, E> Result<T, E> {
609
608
#[ inline]
610
609
#[ stable( feature = "is_some_and" , since = "1.70.0" ) ]
611
610
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
612
- pub const fn is_ok_and ( self , f : impl ~ const FnOnce ( T ) -> bool + ~ const Destruct ) -> bool
611
+ pub const fn is_ok_and < F > ( self , f : F ) -> bool
613
612
where
613
+ F : ~const FnOnce ( T ) -> bool + ~const Destruct ,
614
614
T : ~const Destruct ,
615
615
E : ~const Destruct ,
616
616
{
@@ -663,8 +663,9 @@ impl<T, E> Result<T, E> {
663
663
#[ inline]
664
664
#[ stable( feature = "is_some_and" , since = "1.70.0" ) ]
665
665
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
666
- pub const fn is_err_and ( self , f : impl ~ const FnOnce ( E ) -> bool + ~ const Destruct ) -> bool
666
+ pub const fn is_err_and < F > ( self , f : F ) -> bool
667
667
where
668
+ F : ~const FnOnce ( E ) -> bool + ~const Destruct ,
668
669
E : ~const Destruct ,
669
670
T : ~const Destruct ,
670
671
{
@@ -819,7 +820,10 @@ impl<T, E> Result<T, E> {
819
820
#[ inline]
820
821
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
821
822
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
822
- pub const fn map < U , F : ~const FnOnce ( T ) -> U + ~const Destruct > ( self , op : F ) -> Result < U , E > {
823
+ pub const fn map < U , F > ( self , op : F ) -> Result < U , E >
824
+ where
825
+ F : ~const FnOnce ( T ) -> U + ~const Destruct ,
826
+ {
823
827
match self {
824
828
Ok ( t) => Ok ( op ( t) ) ,
825
829
Err ( e) => Err ( e) ,
@@ -848,8 +852,9 @@ impl<T, E> Result<T, E> {
848
852
#[ stable( feature = "result_map_or" , since = "1.41.0" ) ]
849
853
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
850
854
#[ must_use = "if you don't need the returned value, use `if let` instead" ]
851
- pub const fn map_or < U , F : ~ const FnOnce ( T ) -> U + ~ const Destruct > ( self , default : U , f : F ) -> U
855
+ pub const fn map_or < U , F > ( self , default : U , f : F ) -> U
852
856
where
857
+ F : ~const FnOnce ( T ) -> U + ~const Destruct ,
853
858
T : ~const Destruct ,
854
859
E : ~const Destruct ,
855
860
U : ~const Destruct ,
@@ -881,15 +886,11 @@ impl<T, E> Result<T, E> {
881
886
#[ inline]
882
887
#[ stable( feature = "result_map_or_else" , since = "1.41.0" ) ]
883
888
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
884
- pub const fn map_or_else <
885
- U ,
889
+ pub const fn map_or_else < U , D , F > ( self , default : D , f : F ) -> U
890
+ where
886
891
D : ~const FnOnce ( E ) -> U + ~const Destruct ,
887
892
F : ~const FnOnce ( T ) -> U + ~const Destruct ,
888
- > (
889
- self ,
890
- default : D ,
891
- f : F ,
892
- ) -> U {
893
+ {
893
894
match self {
894
895
Ok ( t) => f ( t) ,
895
896
Err ( e) => default ( e) ,
@@ -918,8 +919,8 @@ impl<T, E> Result<T, E> {
918
919
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
919
920
pub const fn map_or_default < U , F > ( self , f : F ) -> U
920
921
where
921
- U : ~const Default ,
922
922
F : ~const FnOnce ( T ) -> U + ~const Destruct ,
923
+ U : ~const Default ,
923
924
T : ~const Destruct ,
924
925
E : ~const Destruct ,
925
926
{
@@ -950,10 +951,10 @@ impl<T, E> Result<T, E> {
950
951
#[ inline]
951
952
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
952
953
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
953
- pub const fn map_err < F , O : ~ const FnOnce ( E ) -> F + ~ const Destruct > (
954
- self ,
955
- op : O ,
956
- ) -> Result < T , F > {
954
+ pub const fn map_err < F , O > ( self , op : O ) -> Result < T , F >
955
+ where
956
+ O : ~ const FnOnce ( E ) -> F + ~ const Destruct ,
957
+ {
957
958
match self {
958
959
Ok ( t) => Ok ( t) ,
959
960
Err ( e) => Err ( op ( e) ) ,
@@ -976,7 +977,10 @@ impl<T, E> Result<T, E> {
976
977
#[ inline]
977
978
#[ stable( feature = "result_option_inspect" , since = "1.76.0" ) ]
978
979
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
979
- pub const fn inspect < F : ~const FnOnce ( & T ) + ~const Destruct > ( self , f : F ) -> Self {
980
+ pub const fn inspect < F > ( self , f : F ) -> Self
981
+ where
982
+ F : ~const FnOnce ( & T ) + ~const Destruct ,
983
+ {
980
984
if let Ok ( ref t) = self {
981
985
f ( t) ;
982
986
}
@@ -1001,7 +1005,10 @@ impl<T, E> Result<T, E> {
1001
1005
#[ inline]
1002
1006
#[ stable( feature = "result_option_inspect" , since = "1.76.0" ) ]
1003
1007
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
1004
- pub const fn inspect_err < F : ~const FnOnce ( & E ) + ~const Destruct > ( self , f : F ) -> Self {
1008
+ pub const fn inspect_err < F > ( self , f : F ) -> Self
1009
+ where
1010
+ F : ~const FnOnce ( & E ) + ~const Destruct ,
1011
+ {
1005
1012
if let Err ( ref e) = self {
1006
1013
f ( e) ;
1007
1014
}
@@ -1207,8 +1214,7 @@ impl<T, E> Result<T, E> {
1207
1214
#[ inline( always) ]
1208
1215
#[ track_caller]
1209
1216
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1210
- #[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
1211
- pub const fn unwrap ( self ) -> T
1217
+ pub fn unwrap ( self ) -> T
1212
1218
where
1213
1219
E : fmt:: Debug ,
1214
1220
{
@@ -1465,10 +1471,10 @@ impl<T, E> Result<T, E> {
1465
1471
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1466
1472
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
1467
1473
#[ rustc_confusables( "flat_map" , "flatmap" ) ]
1468
- pub const fn and_then < U , F : ~ const FnOnce ( T ) -> Result < U , E > + ~ const Destruct > (
1469
- self ,
1470
- op : F ,
1471
- ) -> Result < U , E > {
1474
+ pub const fn and_then < U , F > ( self , op : F ) -> Result < U , E >
1475
+ where
1476
+ F : ~ const FnOnce ( T ) -> Result < U , E > + ~ const Destruct ,
1477
+ {
1472
1478
match self {
1473
1479
Ok ( t) => op ( t) ,
1474
1480
Err ( e) => Err ( e) ,
@@ -1536,10 +1542,10 @@ impl<T, E> Result<T, E> {
1536
1542
#[ inline]
1537
1543
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1538
1544
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
1539
- pub const fn or_else < F , O : ~ const FnOnce ( E ) -> Result < T , F > + ~ const Destruct > (
1540
- self ,
1541
- op : O ,
1542
- ) -> Result < T , F > {
1545
+ pub const fn or_else < F , O > ( self , op : O ) -> Result < T , F >
1546
+ where
1547
+ O : ~ const FnOnce ( E ) -> Result < T , F > + ~ const Destruct ,
1548
+ {
1543
1549
match self {
1544
1550
Ok ( t) => Ok ( t) ,
1545
1551
Err ( e) => op ( e) ,
@@ -1593,7 +1599,10 @@ impl<T, E> Result<T, E> {
1593
1599
#[ track_caller]
1594
1600
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1595
1601
#[ rustc_const_unstable( feature = "const_result_callback_methods" , issue = "67792" ) ]
1596
- pub const fn unwrap_or_else < F : ~const FnOnce ( E ) -> T + ~const Destruct > ( self , op : F ) -> T {
1602
+ pub const fn unwrap_or_else < F > ( self , op : F ) -> T
1603
+ where
1604
+ F : ~const FnOnce ( E ) -> T + ~const Destruct ,
1605
+ {
1597
1606
match self {
1598
1607
Ok ( t) => t,
1599
1608
Err ( e) => op ( e) ,
@@ -1835,8 +1844,8 @@ impl<T, E> Result<Result<T, E>, E> {
1835
1844
#[ inline( never) ]
1836
1845
#[ cold]
1837
1846
#[ track_caller]
1838
- const fn unwrap_failed ( msg : & str , error : & dyn fmt:: Debug ) -> ! {
1839
- const_panic ! ( "Unwrap failed" , " {msg}: {error:?}", msg : & str = msg , error : & dyn fmt :: Debug = error ) ;
1847
+ fn unwrap_failed ( msg : & str , error : & dyn fmt:: Debug ) -> ! {
1848
+ panic ! ( "{msg}: {error:?}" ) ;
1840
1849
}
1841
1850
1842
1851
// This is a separate function to avoid constructing a `dyn Debug`
0 commit comments