provide_api -> error_generic_member_access
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Tolnay · committed by David Tolnay · parent d6acd22 · Browse files · 6 files·+26 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+26 added−26 removed
- other:+26 added−26 removed
Provenance
- Commit
2b79af8- Tree
1ca4b35- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
d6acd22
6 files changed+26 added−26 removed
modified:src/backtrace.rs+2 added-2 removed
33 unmodified lines34 None35 };36 }37 38-#[cfg(provide_api)]38+#[cfg(error_generic_member_access)]39 macro_rules! backtrace_if_absent {40 ($err:expr) => {41 match std::error::request_ref::<std::backtrace::Backtrace>($err as &dyn std::error::Error) {42 Some(_) => None,1 unmodified line44 }45 };46 }47 48-#[cfg(all(feature = "std", not(provide_api), any(backtrace, feature = "backtrace")))]48+#[cfg(all(feature = "std", not(error_generic_member_access), any(backtrace, feature = "backtrace")))]49 macro_rules! backtrace_if_absent {50 ($err:expr) => {51 backtrace!()52 };349 unmodified linesmodified:src/context.rs+3 added-3 removed
1 unmodified line2 use crate::{Context, Error, StdError};3 use core::convert::Infallible;4 use core::fmt::{self, Debug, Display, Write};5 6-#[cfg(provide_api)]6+#[cfg(error_generic_member_access)]7 use std::error::Request;8 9 mod ext {10 use super::*;131 unmodified lines142 fn source(&self) -> Option<&(dyn StdError + 'static)> {143 Some(&self.error)144 }145 146- #[cfg(provide_api)]146+ #[cfg(error_generic_member_access)]147 fn provide<'a>(&'a self, request: &mut Request<'a>) {148 StdError::provide(&self.error, request);149 }150 }5 unmodified lines156 fn source(&self) -> Option<&(dyn StdError + 'static)> {157 Some(unsafe { crate::ErrorImpl::error(self.error.inner.by_ref()) })158 }159 160- #[cfg(provide_api)]160+ #[cfg(error_generic_member_access)]161 fn provide<'a>(&'a self, request: &mut Request<'a>) {162 Error::provide(&self.error, request);163 }164 }29 unmodified linesmodified:src/error.rs+16 added-16 removed
9 unmodified lines10 use core::mem::ManuallyDrop;11 #[cfg(not(anyhow_no_ptr_addr_of))]12 use core::ptr;13 use core::ptr::NonNull;14-#[cfg(provide_api)]14+#[cfg(error_generic_member_access)]15 use std::error::{self, Request};16 17 #[cfg(feature = "std")]18 use core::ops::{Deref, DerefMut};79 unmodified lines98 object_downcast: object_downcast::<E>,99 #[cfg(anyhow_no_ptr_addr_of)]100 object_downcast_mut: object_downcast_mut::<E>,101 object_drop_rest: object_drop_front::<E>,102- #[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]102+ #[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]103 object_backtrace: no_backtrace,104 };105 106 // Safety: passing vtable that operates on the right type E.16 unmodified lines123 object_downcast: object_downcast::<M>,124 #[cfg(anyhow_no_ptr_addr_of)]125 object_downcast_mut: object_downcast_mut::<M>,126 object_drop_rest: object_drop_front::<M>,127- #[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]127+ #[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]128 object_backtrace: no_backtrace,129 };130 131 // Safety: MessageError is repr(transparent) so it is okay for the17 unmodified lines149 object_downcast: object_downcast::<M>,150 #[cfg(anyhow_no_ptr_addr_of)]151 object_downcast_mut: object_downcast_mut::<M>,152 object_drop_rest: object_drop_front::<M>,153- #[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]153+ #[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]154 object_backtrace: no_backtrace,155 };156 157 // Safety: DisplayError is repr(transparent) so it is okay for the19 unmodified lines177 object_downcast: context_downcast::<C, E>,178 #[cfg(anyhow_no_ptr_addr_of)]179 object_downcast_mut: context_downcast_mut::<C, E>,180 object_drop_rest: context_drop_rest::<C, E>,181- #[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]181+ #[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]182 object_backtrace: no_backtrace,183 };184 185 // Safety: passing vtable that operates on the right type.17 unmodified lines203 object_downcast: object_downcast::<Box<dyn StdError + Send + Sync>>,204 #[cfg(anyhow_no_ptr_addr_of)]205 object_downcast_mut: object_downcast_mut::<Box<dyn StdError + Send + Sync>>,206 object_drop_rest: object_drop_front::<Box<dyn StdError + Send + Sync>>,207- #[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]207+ #[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]208 object_backtrace: no_backtrace,209 };210 211 // Safety: BoxedError is repr(transparent) so it is okay for the vtable104 unmodified lines316 object_downcast: context_chain_downcast::<C>,317 #[cfg(anyhow_no_ptr_addr_of)]318 object_downcast_mut: context_chain_downcast_mut::<C>,319 object_drop_rest: context_chain_drop_rest::<C>,320- #[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]320+ #[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]321 object_backtrace: context_backtrace::<C>,322 };323 324 // As the cause is anyhow::Error, we already have a backtrace for it.193 unmodified lines518 Some(addr.cast::<E>().deref_mut())519 }520 }521 522- #[cfg(provide_api)]522+ #[cfg(error_generic_member_access)]523 pub(crate) fn provide<'a>(&'a self, request: &mut Request<'a>) {524 unsafe { ErrorImpl::provide(self.inner.by_ref(), request) }525 }526 1 unmodified line528 // implementation includes the anyhow::Error's Backtrace if any, unlike529 // deref'ing to dyn Error where the provide implementation would include530 // only the original error's Backtrace from before it got wrapped into an531 // anyhow::Error.532- #[cfg(provide_api)]532+ #[cfg(error_generic_member_access)]533 #[doc(hidden)]534 pub fn thiserror_provide<'a>(&'a self, request: &mut Request<'a>) {535 Self::provide(self, request);536 }60 unmodified lines597 object_downcast: unsafe fn(Ref<ErrorImpl>, TypeId) -> Option<Ref<()>>,598 #[cfg(anyhow_no_ptr_addr_of)]599 object_downcast_mut: unsafe fn(Mut<ErrorImpl>, TypeId) -> Option<Mut<()>>,600 object_drop_rest: unsafe fn(Own<ErrorImpl>, TypeId),601- #[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]601+ #[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]602 object_backtrace: unsafe fn(Ref<ErrorImpl>) -> Option<&Backtrace>,603 }604 605 // Safety: requires layout of *e to match ErrorImpl<E>.96 unmodified lines702 None703 }704 }705 706-#[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]706+#[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]707 fn no_backtrace(e: Ref<ErrorImpl>) -> Option<&Backtrace> {708 let _ = e;709 None710 }112 unmodified lines823 }824 }825 826 // Safety: requires layout of *e to match ErrorImpl<ContextError<C, Error>>.827-#[cfg(all(not(provide_api), any(backtrace, feature = "backtrace")))]827+#[cfg(all(not(error_generic_member_access), any(backtrace, feature = "backtrace")))]828 #[allow(clippy::unnecessary_wraps)]829 unsafe fn context_backtrace<C>(e: Ref<ErrorImpl>) -> Option<&Backtrace>830 where831 C: 'static,71 unmodified lines903 unsafe { this.deref() }904 .backtrace905 .as_ref()906 .or_else(|| {907- #[cfg(provide_api)]907+ #[cfg(error_generic_member_access)]908 return error::request_ref::<Backtrace>(unsafe { Self::error(this) });909- #[cfg(not(provide_api))]909+ #[cfg(not(error_generic_member_access))]910 return unsafe { (vtable(this.ptr).object_backtrace)(this) };911 })912 .expect("backtrace capture failed")913 }914 915- #[cfg(provide_api)]915+ #[cfg(error_generic_member_access)]916 unsafe fn provide<'a>(this: Ref<'a, Self>, request: &mut Request<'a>) {917 if let Some(backtrace) = unsafe { &this.deref().backtrace } {918 request.provide_ref(backtrace);919 }13 unmodified lines933 fn source(&self) -> Option<&(dyn StdError + 'static)> {934 unsafe { ErrorImpl::error(self.erase()).source() }935 }936 937- #[cfg(provide_api)]937+ #[cfg(error_generic_member_access)]938 fn provide<'a>(&'a self, request: &mut Request<'a>) {939 unsafe { ErrorImpl::provide(self.erase(), request) }940 }941 }56 unmodified linesmodified:src/lib.rs+1 added-1 removed
205 unmodified lines206 //! will require an explicit `.map_err(Error::msg)` when working with a207 //! non-Anyhow error type inside a function that returns Anyhow's error type.208 209 #![doc(html_root_url = "https://docs.rs/anyhow/1.0.76")]210-#![cfg_attr(provide_api, feature(error_generic_member_access))]210+#![cfg_attr(error_generic_member_access, feature(error_generic_member_access))]211 #![cfg_attr(doc_cfg, feature(doc_cfg))]212 #![cfg_attr(not(feature = "std"), no_std)]213 #![deny(dead_code, unused_imports, unused_mut)]214 #![cfg_attr(477 unmodified linesmodified:src/wrapper.rs+2 added-2 removed
1 use crate::StdError;2 use core::fmt::{self, Debug, Display};3 4-#[cfg(provide_api)]4+#[cfg(error_generic_member_access)]5 use std::error::Request;6 7 #[repr(transparent)]8 pub struct MessageError<M>(pub M);64 unmodified lines73 fn source(&self) -> Option<&(dyn StdError + 'static)> {74 self.0.source()75 }76 77- #[cfg(provide_api)]77+ #[cfg(error_generic_member_access)]78 fn provide<'a>(&'a self, request: &mut Request<'a>) {79 self.0.provide(request);80 }81 }modified:build.rs+2 added-2 removed
46 unmodified lines47 48 fn main() {49 // If the compile probe succeeds, i.e. if a nightly compiler is used and the50 // provide API exists, then `std::backtrace` is also usable. So `cfg51- // (provide_api)` implies `cfg(backtrace)`. We do set `cfg(backtrace)` in51+ // (error_generic_member_access)` implies `cfg(backtrace)`. We do set `cfg(backtrace)` in52 // this script explicitly anyway to make the `cfg()` attributes in the main53 // code less complex.54 let mut nightly_backtrace_support = false;55 if cfg!(feature = "std") {56 println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");57 58 match compile_probe() {59 Some(status) if status.success() => {60- println!("cargo:rustc-cfg=provide_api");60+ println!("cargo:rustc-cfg=error_generic_member_access");61 nightly_backtrace_support = true;62 }63 _ => {}64 }90 unmodified lines