@@ -684,16 +684,10 @@ impl<T, E: fmt::Debug> Result<T, E> {
684
684
pub fn unwrap ( self ) -> T {
685
685
match self {
686
686
Ok ( t) => t,
687
- Err ( e) => Self :: unwrap_failed ( e) ,
687
+ Err ( e) => unwrap_failed ( "called `Result::unwrap()` on an `Err` value" , e) ,
688
688
}
689
689
}
690
690
691
- #[ inline( never) ]
692
- #[ cold]
693
- fn unwrap_failed ( error : E ) -> ! {
694
- panic ! ( "called `Result::unwrap()` on an `Err` value: {:?}" , error)
695
- }
696
-
697
691
/// Unwraps a result, yielding the content of an `Ok`.
698
692
///
699
693
/// # Panics
@@ -711,15 +705,9 @@ impl<T, E: fmt::Debug> Result<T, E> {
711
705
pub fn expect ( self , msg : & str ) -> T {
712
706
match self {
713
707
Ok ( t) => t,
714
- Err ( e) => Self :: expect_failed ( msg, e) ,
708
+ Err ( e) => unwrap_failed ( msg, e) ,
715
709
}
716
710
}
717
-
718
- #[ inline( never) ]
719
- #[ cold]
720
- fn expect_failed ( msg : & str , error : E ) -> ! {
721
- panic ! ( "{}: {:?}" , msg, error)
722
- }
723
711
}
724
712
725
713
impl < T : fmt:: Debug , E > Result < T , E > {
@@ -745,17 +733,17 @@ impl<T: fmt::Debug, E> Result<T, E> {
745
733
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
746
734
pub fn unwrap_err ( self ) -> E {
747
735
match self {
748
- Ok ( t) => Self :: unwrap_err_failed ( t) ,
736
+ Ok ( t) => unwrap_failed ( "called `Result::unwrap_err()` on an `Ok` value" , t) ,
749
737
Err ( e) => e,
750
738
}
751
739
}
740
+ }
752
741
753
- #[ inline( never) ]
754
- #[ cold]
755
- fn unwrap_err_failed ( t : T ) -> ! {
756
- panic ! ( "called `Result::unwrap_err()` on an `Ok` value: {:?}" , t)
757
- }
758
-
742
+ // This is a separate function to reduce the code size of the methods
743
+ #[ inline( never) ]
744
+ #[ cold]
745
+ fn unwrap_failed < E : fmt:: Debug > ( msg : & str , error : E ) -> ! {
746
+ panic ! ( "{}: {:?}" , msg, error)
759
747
}
760
748
761
749
/////////////////////////////////////////////////////////////////////////////
0 commit comments