@@ -260,20 +260,6 @@ pub trait Error: Debug + Display {
260
260
TypeId :: of :: < Self > ( )
261
261
}
262
262
263
- /// Returns a stack backtrace, if available, of where this error occurred.
264
- ///
265
- /// This function allows inspecting the location, in code, of where an error
266
- /// happened. The returned `Backtrace` contains information about the stack
267
- /// trace of the OS thread of execution of where the error originated from.
268
- ///
269
- /// Note that not all errors contain a `Backtrace`. Also note that a
270
- /// `Backtrace` may actually be empty. For more information consult the
271
- /// `Backtrace` type itself.
272
- #[ unstable( feature = "backtrace" , issue = "53487" ) ]
273
- fn backtrace ( & self ) -> Option < & Backtrace > {
274
- None
275
- }
276
-
277
263
/// ```
278
264
/// if let Err(e) = "xc".parse::<u32>() {
279
265
/// // Print `e` itself, no need for description().
@@ -370,7 +356,7 @@ pub trait Error: Debug + Display {
370
356
}
371
357
372
358
#[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
373
- impl Provider for dyn Error + ' static {
359
+ impl < ' b > Provider for dyn Error + ' b {
374
360
fn provide < ' a > ( & ' a self , req : & mut Demand < ' a > ) {
375
361
self . provide ( req)
376
362
}
@@ -757,8 +743,8 @@ impl<'a, T: Error + ?Sized> Error for &'a T {
757
743
Error :: source ( & * * self )
758
744
}
759
745
760
- fn backtrace ( & self ) -> Option < & Backtrace > {
761
- Error :: backtrace ( & * * self )
746
+ fn provide < ' b > ( & ' b self , req : & mut Demand < ' b > ) {
747
+ Error :: provide ( & * * self , req ) ;
762
748
}
763
749
}
764
750
@@ -778,8 +764,8 @@ impl<T: Error + ?Sized> Error for Arc<T> {
778
764
Error :: source ( & * * self )
779
765
}
780
766
781
- fn backtrace ( & self ) -> Option < & Backtrace > {
782
- Error :: backtrace ( & * * self )
767
+ fn provide < ' a > ( & ' a self , req : & mut Demand < ' a > ) {
768
+ Error :: provide ( & * * self , req ) ;
783
769
}
784
770
}
785
771
@@ -871,6 +857,20 @@ impl Error for alloc::ffi::IntoStringError {
871
857
}
872
858
}
873
859
860
+ impl < ' a > dyn Error + ' a {
861
+ /// Request a reference of type `T` as context about this error.
862
+ #[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
863
+ pub fn request_ref < T : ?Sized + ' static > ( & ' a self ) -> Option < & ' a T > {
864
+ core:: any:: request_ref ( self )
865
+ }
866
+
867
+ /// Request a value of type `T` as context about this error.
868
+ #[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
869
+ pub fn request_value < T : ' static > ( & ' a self ) -> Option < T > {
870
+ core:: any:: request_value ( self )
871
+ }
872
+ }
873
+
874
874
// Copied from `any.rs`.
875
875
impl dyn Error + ' static {
876
876
/// Returns `true` if the inner type is the same as `T`.
@@ -910,18 +910,6 @@ impl dyn Error + 'static {
910
910
None
911
911
}
912
912
}
913
-
914
- /// Request a reference of type `T` as context about this error.
915
- #[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
916
- pub fn request_ref < T : ?Sized + ' static > ( & self ) -> Option < & T > {
917
- core:: any:: request_ref ( self )
918
- }
919
-
920
- /// Request a value of type `T` as context about this error.
921
- #[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
922
- pub fn request_value < T : ' static > ( & self ) -> Option < T > {
923
- core:: any:: request_value ( self )
924
- }
925
913
}
926
914
927
915
impl dyn Error + ' static + Send {
@@ -949,13 +937,13 @@ impl dyn Error + 'static + Send {
949
937
/// Request a reference of type `T` as context about this error.
950
938
#[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
951
939
pub fn request_ref < T : ?Sized + ' static > ( & self ) -> Option < & T > {
952
- <dyn Error + ' static >:: request_ref ( self )
940
+ <dyn Error >:: request_ref ( self )
953
941
}
954
942
955
943
/// Request a value of type `T` as context about this error.
956
944
#[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
957
945
pub fn request_value < T : ' static > ( & self ) -> Option < T > {
958
- <dyn Error + ' static >:: request_value ( self )
946
+ <dyn Error >:: request_value ( self )
959
947
}
960
948
}
961
949
@@ -984,13 +972,13 @@ impl dyn Error + 'static + Send + Sync {
984
972
/// Request a reference of type `T` as context about this error.
985
973
#[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
986
974
pub fn request_ref < T : ?Sized + ' static > ( & self ) -> Option < & T > {
987
- <dyn Error + ' static >:: request_ref ( self )
975
+ <dyn Error >:: request_ref ( self )
988
976
}
989
977
990
978
/// Request a value of type `T` as context about this error.
991
979
#[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
992
980
pub fn request_value < T : ' static > ( & self ) -> Option < T > {
993
- <dyn Error + ' static >:: request_value ( self )
981
+ <dyn Error >:: request_value ( self )
994
982
}
995
983
}
996
984
@@ -1467,8 +1455,11 @@ impl<E> Report<E> {
1467
1455
/// ```rust
1468
1456
/// #![feature(error_reporter)]
1469
1457
/// #![feature(backtrace)]
1458
+ /// #![feature(provide_any)]
1459
+ /// #![feature(error_generic_member_access)]
1470
1460
/// # use std::error::Error;
1471
1461
/// # use std::fmt;
1462
+ /// use std::any::Demand;
1472
1463
/// use std::error::Report;
1473
1464
/// use std::backtrace::Backtrace;
1474
1465
///
@@ -1498,8 +1489,9 @@ impl<E> Report<E> {
1498
1489
/// }
1499
1490
///
1500
1491
/// impl Error for SuperErrorSideKick {
1501
- /// fn backtrace(&self) -> Option<&Backtrace> {
1502
- /// Some(&self.backtrace)
1492
+ /// fn provide<'a>(&'a self, req: &mut Demand<'a>) {
1493
+ /// req
1494
+ /// .provide_ref::<Backtrace>(&self.backtrace);
1503
1495
/// }
1504
1496
/// }
1505
1497
///
@@ -1552,11 +1544,11 @@ where
1552
1544
fn backtrace ( & self ) -> Option < & Backtrace > {
1553
1545
// have to grab the backtrace on the first error directly since that error may not be
1554
1546
// 'static
1555
- let backtrace = self . error . backtrace ( ) ;
1547
+ let backtrace = ( & self . error as & dyn Error ) . request_ref ( ) ;
1556
1548
let backtrace = backtrace. or_else ( || {
1557
1549
self . error
1558
1550
. source ( )
1559
- . map ( |source| source. chain ( ) . find_map ( |source| source. backtrace ( ) ) )
1551
+ . map ( |source| source. chain ( ) . find_map ( |source| source. request_ref ( ) ) )
1560
1552
. flatten ( )
1561
1553
} ) ;
1562
1554
backtrace
@@ -1618,11 +1610,11 @@ impl Report<Box<dyn Error>> {
1618
1610
fn backtrace ( & self ) -> Option < & Backtrace > {
1619
1611
// have to grab the backtrace on the first error directly since that error may not be
1620
1612
// 'static
1621
- let backtrace = self . error . backtrace ( ) ;
1613
+ let backtrace = self . error . request_ref ( ) ;
1622
1614
let backtrace = backtrace. or_else ( || {
1623
1615
self . error
1624
1616
. source ( )
1625
- . map ( |source| source. chain ( ) . find_map ( |source| source. backtrace ( ) ) )
1617
+ . map ( |source| source. chain ( ) . find_map ( |source| source. request_ref ( ) ) )
1626
1618
. flatten ( )
1627
1619
} ) ;
1628
1620
backtrace
0 commit comments