/rust/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.98/src/nightly.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // This code exercises the surface area that we expect of the Error generic |
2 | | // member access API. If the current toolchain is able to compile it, then |
3 | | // anyhow is able to provide backtrace support. |
4 | | |
5 | | #![cfg_attr(anyhow_build_probe, feature(error_generic_member_access))] |
6 | | |
7 | | use core::error::{self, Error}; |
8 | | use std::backtrace::Backtrace; |
9 | | |
10 | | pub use core::error::Request; |
11 | | |
12 | | #[cfg(anyhow_build_probe)] |
13 | | const _: () = { |
14 | | use core::fmt::{self, Debug, Display}; |
15 | | |
16 | | struct MyError(Backtrace); |
17 | | |
18 | | impl Debug for MyError { |
19 | | fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { |
20 | | unimplemented!() |
21 | | } |
22 | | } |
23 | | |
24 | | impl Display for MyError { |
25 | | fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { |
26 | | unimplemented!() |
27 | | } |
28 | | } |
29 | | |
30 | | impl Error for MyError { |
31 | | fn provide<'a>(&'a self, request: &mut Request<'a>) { |
32 | | provide_ref_backtrace(request, &self.0); |
33 | | } |
34 | | } |
35 | | }; |
36 | | |
37 | | // Include in sccache cache key. |
38 | | #[cfg(anyhow_build_probe)] |
39 | | const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP"); |
40 | | |
41 | 0 | pub fn request_ref_backtrace(err: &dyn Error) -> Option<&Backtrace> { |
42 | 0 | request_ref::<Backtrace>(err) |
43 | 0 | } |
44 | | |
45 | 0 | fn request_ref<'a, T>(err: &'a (impl Error + ?Sized)) -> Option<&'a T> |
46 | 0 | where |
47 | 0 | T: 'static + ?Sized, |
48 | 0 | { |
49 | 0 | error::request_ref::<T>(err) |
50 | 0 | } |
51 | | |
52 | 0 | pub fn provide_ref_backtrace<'a>(request: &mut Request<'a>, backtrace: &'a Backtrace) { |
53 | 0 | Request::provide_ref(request, backtrace); |
54 | 0 | } |
55 | | |
56 | 0 | pub fn provide<'a>(err: &'a (impl Error + ?Sized), request: &mut Request<'a>) { |
57 | 0 | Error::provide(err, request); |
58 | 0 | } |