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