Skip to content
Myr

Merge pull request #414 from dtolnay/nightly

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Make all nightly go through the module that was probed

authored by David Tolnay · committed by GitHub · parents bfb89ef, 02aa6b6 · Browse files · 8 files+74 added−48 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+74 added−48 removed

  • other:+74 added−48 removed

8 files+74 added−48 removed

deleted:build/probe.rs-35 removed
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#![feature(error_generic_member_access)]67use core::error::{self, Error, Request};8use core::fmt::{self, Debug, Display};9use std::backtrace::Backtrace;1011struct MyError(Thing);12struct Thing;1314impl Debug for MyError {15 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {16 unimplemented!()17 }18}1920impl Display for MyError {21 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {22 unimplemented!()23 }24}2526impl Error for MyError {27 fn provide<'a>(&'a self, request: &mut Request<'a>) {28 request.provide_ref(&self.0);29 }30}3132const _: fn(&dyn Error) -> Option<&Backtrace> = |err| error::request_ref::<Backtrace>(err);3334// Include in sccache cache key.35const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");
modified:src/backtrace.rs+1 added-2 removed
36 unmodified lines
3738#[cfg(error_generic_member_access)]39macro_rules! backtrace_if_absent {40 ($err:expr) => {41 match core::error::request_ref::<std::backtrace::Backtrace>($err as &dyn core::error::Error)42 {41 match $crate::nightly::request_ref_backtrace($err as &dyn core::error::Error) {42 Some(_) => None,43 None => backtrace!(),44 }45 };
365 unmodified lines
modified:src/context.rs+2 added-2 removed
2 unmodified lines
3use core::convert::Infallible;4use core::fmt::{self, Debug, Display, Write};56#[cfg(error_generic_member_access)]7use core::error::Request;7use crate::nightly::{self, Request};89mod ext {10 use super::*;11
132 unmodified lines
144 }145146 #[cfg(error_generic_member_access)]147 fn provide<'a>(&'a self, request: &mut Request<'a>) {148 StdError::provide(&self.error, request);148 nightly::provide(&self.error, request);149 }150}151152impl<C> StdError for ContextError<C, Error>
41 unmodified lines
modified:src/error.rs+5 added-5 removed
1use crate::backtrace::Backtrace;2use crate::chain::Chain;3#[cfg(error_generic_member_access)]4use crate::nightly::{self, Request};5#[cfg(any(feature = "std", not(anyhow_no_core_error), anyhow_no_ptr_addr_of))]6use crate::ptr::Mut;7use crate::ptr::{Own, Ref};8use crate::{Error, StdError};9use alloc::boxed::Box;10use core::any::TypeId;9#[cfg(error_generic_member_access)]10use core::error::{self, Request};11use core::fmt::{self, Debug, Display};12use core::mem::ManuallyDrop;13#[cfg(any(feature = "std", not(anyhow_no_core_error)))]14use core::ops::{Deref, DerefMut};
979 unmodified lines
994 .backtrace995 .as_ref()996 .or_else(|| {997 #[cfg(error_generic_member_access)]998 return error::request_ref::<Backtrace>(unsafe { Self::error(this) });998 return nightly::request_ref_backtrace(unsafe { Self::error(this) });999 #[cfg(not(error_generic_member_access))]1000 return unsafe { (vtable(this.ptr).object_backtrace)(this) };1001 })1002 .expect("backtrace capture failed")
1 unmodified line
10041005 #[cfg(error_generic_member_access)]1006 unsafe fn provide<'a>(this: Ref<'a, Self>, request: &mut Request<'a>) {1007 if let Some(backtrace) = unsafe { &this.deref().backtrace } {1008 request.provide_ref(backtrace);1008 nightly::provide_ref_backtrace(request, backtrace);1009 }1010 unsafe { Self::error(this) }.provide(request);1010 nightly::provide(unsafe { Self::error(this) }, request);1011 }10121013 #[cold]1014 pub(crate) unsafe fn chain(this: Ref<Self>) -> Chain {
79 unmodified lines
modified:src/lib.rs+2 added
258 unmodified lines
259mod error;260mod fmt;261mod kind;262mod macros;263#[cfg(error_generic_member_access)]264mod nightly;265mod ptr;266mod wrapper;267268use crate::error::ErrorImpl;
467 unmodified lines
added:src/nightly.rs+58 added
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}
modified:src/wrapper.rs+2 added-2 removed
3 unmodified lines
4#[cfg(any(feature = "std", not(anyhow_no_core_error)))]5use alloc::boxed::Box;67#[cfg(error_generic_member_access)]8use core::error::Request;8use crate::nightly::{self, Request};910#[repr(transparent)]11pub struct MessageError<M>(pub M);12
65 unmodified lines
78 }7980 #[cfg(error_generic_member_access)]81 fn provide<'a>(&'a self, request: &mut Request<'a>) {82 self.0.provide(request);82 nightly::provide(&*self.0, request);83 }84}
modified:build.rs+4 added-2 removed
13 unmodified lines
1415fn main() {16 let mut error_generic_member_access = false;17 if cfg!(feature = "std") {18 println!("cargo:rerun-if-changed=build/probe.rs");18 println!("cargo:rerun-if-changed=src/nightly.rs");1920 let consider_rustc_bootstrap;21 if compile_probe(false) {22 // This is a nightly or dev compiler, so it supports unstable
44 unmodified lines
67 None => return,68 };6970 if rustc >= 80 {71 println!("cargo:rustc-check-cfg=cfg(anyhow_build_probe)");72 println!("cargo:rustc-check-cfg=cfg(anyhow_nightly_testing)");73 println!("cargo:rustc-check-cfg=cfg(anyhow_no_core_error)");74 println!("cargo:rustc-check-cfg=cfg(anyhow_no_core_unwind_safe)");75 println!("cargo:rustc-check-cfg=cfg(anyhow_no_fmt_arguments_as_str)");
52 unmodified lines
128129 let rustc = cargo_env_var("RUSTC");130 let out_dir = cargo_env_var("OUT_DIR");131 let out_subdir = Path::new(&out_dir).join("probe");131 let probefile = Path::new("build").join("probe.rs");132 let probefile = Path::new("src").join("nightly.rs");133134 if let Err(err) = fs::create_dir(&out_subdir) {135 if err.kind() != ErrorKind::AlreadyExists {136 eprintln!("Failed to create {}: {}", out_subdir.display(), err);
15 unmodified lines
152 cmd.env_remove("RUSTC_BOOTSTRAP");153 }154155 cmd.stderr(Stdio::null())156 .arg("--cfg=anyhow_build_probe")157 .arg("--edition=2018")158 .arg("--crate-name=anyhow")159 .arg("--crate-type=lib")160 .arg("--emit=dep-info,metadata")
56 unmodified lines