@@ -684,16 +684,10 @@ impl<T, E: fmt::Debug> Result<T, E> {
684684 pub fn unwrap ( self ) -> T {
685685 match self {
686686 Ok ( t) => t,
687- Err ( e) => Self :: unwrap_failed ( e) ,
687+ Err ( e) => unwrap_failed ( "called `Result::unwrap()` on an `Err` value" , e) ,
688688 }
689689 }
690690
691- #[ inline( never) ]
692- #[ cold]
693- fn unwrap_failed ( error : E ) -> ! {
694- panic ! ( "called `Result::unwrap()` on an `Err` value: {:?}" , error)
695- }
696-
697691 /// Unwraps a result, yielding the content of an `Ok`.
698692 ///
699693 /// # Panics
@@ -711,15 +705,9 @@ impl<T, E: fmt::Debug> Result<T, E> {
711705 pub fn expect ( self , msg : & str ) -> T {
712706 match self {
713707 Ok ( t) => t,
714- Err ( e) => Self :: expect_failed ( msg, e) ,
708+ Err ( e) => unwrap_failed ( msg, e) ,
715709 }
716710 }
717-
718- #[ inline( never) ]
719- #[ cold]
720- fn expect_failed ( msg : & str , error : E ) -> ! {
721- panic ! ( "{}: {:?}" , msg, error)
722- }
723711}
724712
725713impl < T : fmt:: Debug , E > Result < T , E > {
@@ -745,17 +733,17 @@ impl<T: fmt::Debug, E> Result<T, E> {
745733 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
746734 pub fn unwrap_err ( self ) -> E {
747735 match self {
748- Ok ( t) => Self :: unwrap_err_failed ( t) ,
736+ Ok ( t) => unwrap_failed ( "called `Result::unwrap_err()` on an `Ok` value" , t) ,
749737 Err ( e) => e,
750738 }
751739 }
740+ }
752741
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)
759747}
760748
761749/////////////////////////////////////////////////////////////////////////////
0 commit comments