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
Provenance
- Commit
213a9c2- Tree
a62c8aa- Author
David Tolnay <dtolnay@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
bfb89ef- Parent 2
02aa6b6
8 files changed+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.4-5-#![feature(error_generic_member_access)]6-7-use core::error::{self, Error, Request};8-use core::fmt::{self, Debug, Display};9-use std::backtrace::Backtrace;10-11-struct MyError(Thing);12-struct Thing;13-14-impl Debug for MyError {15- fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {16- unimplemented!()17- }18-}19-20-impl Display for MyError {21- fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {22- unimplemented!()23- }24-}25-26-impl Error for MyError {27- fn provide<'a>(&'a self, request: &mut Request<'a>) {28- request.provide_ref(&self.0);29- }30-}31-32-const _: fn(&dyn Error) -> Option<&Backtrace> = |err| error::request_ref::<Backtrace>(err);33-34-// Include in sccache cache key.35-const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");modified:src/backtrace.rs+1 added-2 removed
36 unmodified lines37 38 #[cfg(error_generic_member_access)]39 macro_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 linesmodified:src/context.rs+2 added-2 removed
2 unmodified lines3 use core::convert::Infallible;4 use core::fmt::{self, Debug, Display, Write};5 6 #[cfg(error_generic_member_access)]7-use core::error::Request;7+use crate::nightly::{self, Request};8 9 mod ext {10 use super::*;11 132 unmodified lines144 }145 146 #[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 }151 152 impl<C> StdError for ContextError<C, Error>41 unmodified linesmodified:src/error.rs+5 added-5 removed
1 use crate::backtrace::Backtrace;2 use crate::chain::Chain;3+#[cfg(error_generic_member_access)]4+use crate::nightly::{self, Request};5 #[cfg(any(feature = "std", not(anyhow_no_core_error), anyhow_no_ptr_addr_of))]6 use crate::ptr::Mut;7 use crate::ptr::{Own, Ref};8 use crate::{Error, StdError};9 use alloc::boxed::Box;10 use core::any::TypeId;9-#[cfg(error_generic_member_access)]10-use core::error::{self, Request};11 use core::fmt::{self, Debug, Display};12 use core::mem::ManuallyDrop;13 #[cfg(any(feature = "std", not(anyhow_no_core_error)))]14 use core::ops::{Deref, DerefMut};979 unmodified lines994 .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 line1004 1005 #[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 }1012 1013 #[cold]1014 pub(crate) unsafe fn chain(this: Ref<Self>) -> Chain {79 unmodified linesmodified:src/lib.rs+2 added
258 unmodified lines259 mod error;260 mod fmt;261 mod kind;262 mod macros;263+#[cfg(error_generic_member_access)]264+mod nightly;265 mod ptr;266 mod wrapper;267 268 use crate::error::ErrorImpl;467 unmodified linesadded: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.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+pub fn request_ref_backtrace(err: &dyn Error) -> Option<&Backtrace> {42+ request_ref::<Backtrace>(err)43+}44+45+fn request_ref<'a, T>(err: &'a (impl Error + ?Sized)) -> Option<&'a T>46+where47+ T: 'static + ?Sized,48+{49+ error::request_ref::<T>(err)50+}51+52+pub fn provide_ref_backtrace<'a>(request: &mut Request<'a>, backtrace: &'a Backtrace) {53+ Request::provide_ref(request, backtrace);54+}55+56+pub 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 lines4 #[cfg(any(feature = "std", not(anyhow_no_core_error)))]5 use alloc::boxed::Box;6 7 #[cfg(error_generic_member_access)]8-use core::error::Request;8+use crate::nightly::{self, Request};9 10 #[repr(transparent)]11 pub struct MessageError<M>(pub M);12 65 unmodified lines78 }79 80 #[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 lines14 15 fn 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");19 20 let consider_rustc_bootstrap;21 if compile_probe(false) {22 // This is a nightly or dev compiler, so it supports unstable44 unmodified lines67 None => return,68 };69 70 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 lines128 129 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");133 134 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 lines152 cmd.env_remove("RUSTC_BOOTSTRAP");153 }154 155 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