nightly.rs
This file
Path
src/nightly.rs
58 lines · 1.5 KiB · Rust
Last changed by
Merge pull request #414 from dtolnay/nightlyDavid Tolnaybefore adoption213a9c2
History of this fileTake it
1// This code exercises the surface area that we expect of the Error generic2// member access API. If the current toolchain is able to compile it, then3// anyhow is able to provide backtrace support.45#![cfg_attr(anyhow_build_probe, feature(error_generic_member_access))]67use core::error::{self, Error};8use std::backtrace::Backtrace;910pub use core::error::Request;1112#[cfg(anyhow_build_probe)]13const _: () = {14 use core::fmt::{self, Debug, Display};1516 struct MyError(Backtrace);1718 impl Debug for MyError {19 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {20 unimplemented!()21 }22 }2324 impl Display for MyError {25 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {26 unimplemented!()27 }28 }2930 impl Error for MyError {31 fn provide<'a>(&'a self, request: &mut Request<'a>) {32 provide_ref_backtrace(request, &self.0);33 }34 }35};3637// Include in sccache cache key.38#[cfg(anyhow_build_probe)]39const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");4041pub fn request_ref_backtrace(err: &dyn Error) -> Option<&Backtrace> {42 request_ref::<Backtrace>(err)43}4445fn request_ref<'a, T>(err: &'a (impl Error + ?Sized)) -> Option<&'a T>46where47 T: 'static + ?Sized,48{49 error::request_ref::<T>(err)50}5152pub fn provide_ref_backtrace<'a>(request: &mut Request<'a>, backtrace: &'a Backtrace) {53 Request::provide_ref(request, backtrace);54}5556pub fn provide<'a>(err: &'a (impl Error + ?Sized), request: &mut Request<'a>) {57 Error::provide(err, request);58}