From 541f88a3d86f87cd470171adec7ab74374489e6c Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 13:10:40 +0800 Subject: [PATCH 1/9] add backtrace feature Signed-off-by: Bugen Zhao --- Cargo.toml | 3 +++ derive/Cargo.toml | 3 +++ derive/src/expand.rs | 16 ++++++++++++++-- rust-toolchain.toml | 2 +- src/backtrace.rs | 42 +++++++++++++++++++++++++----------------- src/lib.rs | 6 ++++-- src/ptr.rs | 1 + src/report.rs | 13 +++++++------ tests/basic.rs | 2 +- 9 files changed, 59 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 26c6fd4..92e21cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,9 @@ anyhow = "1" expect-test = "1" sealed_test = "1" +[features] +backtrace = ["thiserror-ext-derive/backtrace"] + [workspace] members = ["derive"] package.version = "0.1.2" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 67a3a80..a832368 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -12,6 +12,9 @@ license = { workspace = true } [lib] proc-macro = true +[features] +backtrace = [] + [dependencies] either = "1" proc-macro2 = "1" diff --git a/derive/src/expand.rs b/derive/src/expand.rs index 49b4f3a..cc224c6 100644 --- a/derive/src/expand.rs +++ b/derive/src/expand.rs @@ -153,7 +153,14 @@ fn resolve_meta(input: &DeriveInput) -> Result { let value = meta.value()?; new_type = Some(value.parse()?); } else if meta.path.is_ident("backtrace") { - nt_backtrace = true; + if cfg!(feature = "backtrace") { + nt_backtrace = true; + } else { + return Err(Error::new_spanned( + meta.path, + "enable the `backtrace` feature to use `backtrace` attribute", + )); + } } else { return Err(Error::new_spanned(meta.path, "unknown attribute")); } @@ -274,6 +281,11 @@ pub fn derive_new_type(input: &DeriveInput, ty: DeriveNewType) -> Result quote!(), DeriveNewType::Arc => quote!(Clone), }; + let backtrace_attr = if cfg!(feature = "backtrace") { + quote!(#[backtrace]) + } else { + quote!() + }; let into_inner = match ty { DeriveNewType::Box => quote!( @@ -291,7 +303,7 @@ pub fn derive_new_type(input: &DeriveInput, ty: DeriveNewType) -> Result Self; + #[cfg(feature = "backtrace")] /// Provide the backtrace, if any. fn provide<'a>(&'a self, request: &mut std::error::Request<'a>); } @@ -13,30 +12,39 @@ pub trait WithBacktrace { #[derive(Clone, Copy)] pub struct NoExtraBacktrace; -/// Capture backtrace if the error does not already have one. -pub struct MaybeBacktrace(Option); - impl WithBacktrace for NoExtraBacktrace { fn capture(_inner: &dyn std::error::Error) -> Self { Self } + #[cfg(feature = "backtrace")] fn provide<'a>(&'a self, _request: &mut std::error::Request<'a>) {} } -impl WithBacktrace for MaybeBacktrace { - fn capture(inner: &dyn std::error::Error) -> Self { - let inner = if std::error::request_ref::(inner).is_none() { - Some(Backtrace::capture()) - } else { - None - }; - Self(inner) - } +#[cfg(feature = "backtrace")] +mod maybe { + use std::backtrace::Backtrace; + + /// Capture backtrace if the error does not already have one. + pub struct MaybeBacktrace(Option); + + impl WithBacktrace for MaybeBacktrace { + fn capture(inner: &dyn std::error::Error) -> Self { + let inner = if std::error::request_ref::(inner).is_none() { + Some(Backtrace::capture()) + } else { + None + }; + Self(inner) + } - fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) { - if let Some(backtrace) = &self.0 { - request.provide_ref(backtrace); + fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) { + if let Some(backtrace) = &self.0 { + request.provide_ref(backtrace); + } } } } + +#[cfg(feature = "backtrace")] +pub use maybe::MaybeBacktrace; diff --git a/src/lib.rs b/src/lib.rs index 2cf21aa..ca1b16a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ //! wrap an `enum` error type into a new type, reducing the size to improve //! performance, and automatically capturing backtraces if needed. -#![feature(error_generic_member_access)] // TODO: it's nightly-only +#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] mod as_dyn; mod backtrace; @@ -30,7 +30,9 @@ pub use thiserror_ext_derive::*; #[doc(hidden)] pub mod __private { - pub use crate::backtrace::{MaybeBacktrace, NoExtraBacktrace}; + #[cfg(feature = "backtrace")] + pub use crate::backtrace::MaybeBacktrace; + pub use crate::backtrace::NoExtraBacktrace; pub use crate::ptr::{ErrorArc, ErrorBox}; pub use thiserror; } diff --git a/src/ptr.rs b/src/ptr.rs index fe0ca16..57f8024 100644 --- a/src/ptr.rs +++ b/src/ptr.rs @@ -78,6 +78,7 @@ macro_rules! impl_methods { } // https://github.com/rust-lang/rust/issues/117432 + #[cfg(feature = "backtrace")] fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) { self.backtrace().provide(request); T::provide(self.inner(), request); diff --git a/src/report.rs b/src/report.rs index 0ee8f69..4301e1d 100644 --- a/src/report.rs +++ b/src/report.rs @@ -187,15 +187,16 @@ impl<'a> fmt::Display for Report<'a> { impl<'a> fmt::Debug for Report<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // Hack for testing purposes. - // Read the env var could be slow but we short-circuit it in release mode, - // so this should be optimized out in production. - let force_show_backtrace = cfg!(debug_assertions) - && std::env::var("THISERROR_EXT_TEST_SHOW_USELESS_BACKTRACE").is_ok(); - self.cleaned_error_trace(f, f.alternate())?; + #[cfg(feature = "backtrace")] if let Some(bt) = std::error::request_ref::(self.0) { + // Hack for testing purposes. + // Read the env var could be slow but we short-circuit it in release mode, + // so this should be optimized out in production. + let force_show_backtrace = cfg!(debug_assertions) + && std::env::var("THISERROR_EXT_TEST_SHOW_USELESS_BACKTRACE").is_ok(); + // If the backtrace is disabled or unsupported, behave as if there's no backtrace. if bt.status() == BacktraceStatus::Captured || force_show_backtrace { // The alternate mode contains a trailing newline while non-alternate diff --git a/tests/basic.rs b/tests/basic.rs index 57186d0..9f85957 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,4 +1,4 @@ -#![feature(error_generic_member_access)] +// #![feature(error_generic_member_access)] use std::backtrace::Backtrace; use thiserror::*; From 9153f1ceda132c4143d37487be2dfc0820bbbdc5 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 13:26:36 +0800 Subject: [PATCH 2/9] fix tests Signed-off-by: Bugen Zhao --- examples/context.rs | 2 +- rust-toolchain.toml | 2 +- src/ptr.rs | 1 + src/report.rs | 37 +++++++++++++++++++------------------ tests/arc_new_type.rs | 2 +- tests/backtrace.rs | 1 + tests/basic.rs | 5 ++++- tests/context_into.rs | 2 +- tests/macro.rs | 2 +- tests/report.rs | 2 +- tests/report_debug.rs | 2 +- 11 files changed, 32 insertions(+), 26 deletions(-) diff --git a/examples/context.rs b/examples/context.rs index 8fcedce..79e6b22 100644 --- a/examples/context.rs +++ b/examples/context.rs @@ -1,7 +1,7 @@ //! This example demonstrates how to achieve the similar functionality as //! [`anyhow::Context`] with `thiserror_ext`, in a type-safer manner. -#![feature(error_generic_member_access)] +#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] use thiserror::Error; use thiserror_ext::{AsReport, Box, ContextInto, Macro}; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 83a52c3..fcc85b9 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.76" +channel = "1.77" diff --git a/src/ptr.rs b/src/ptr.rs index 57f8024..89cc6c5 100644 --- a/src/ptr.rs +++ b/src/ptr.rs @@ -43,6 +43,7 @@ macro_rules! impl_methods { } impl $ty { + #[cfg_attr(not(feature = "backtrace"), allow(dead_code))] fn backtrace(&self) -> &B { &self.0.as_ref().1 } diff --git a/src/report.rs b/src/report.rs index 4301e1d..0d0373e 100644 --- a/src/report.rs +++ b/src/report.rs @@ -15,10 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{ - backtrace::{Backtrace, BacktraceStatus}, - fmt, -}; +use std::fmt; /// Extension trait for [`Error`] that provides a [`Report`] which formats /// the error and its sources in a cleaned-up way. @@ -190,21 +187,25 @@ impl<'a> fmt::Debug for Report<'a> { self.cleaned_error_trace(f, f.alternate())?; #[cfg(feature = "backtrace")] - if let Some(bt) = std::error::request_ref::(self.0) { - // Hack for testing purposes. - // Read the env var could be slow but we short-circuit it in release mode, - // so this should be optimized out in production. - let force_show_backtrace = cfg!(debug_assertions) - && std::env::var("THISERROR_EXT_TEST_SHOW_USELESS_BACKTRACE").is_ok(); - - // If the backtrace is disabled or unsupported, behave as if there's no backtrace. - if bt.status() == BacktraceStatus::Captured || force_show_backtrace { - // The alternate mode contains a trailing newline while non-alternate - // mode does not. So we need to add a newline before the backtrace. - if !f.alternate() { - writeln!(f)?; + { + use std::backtrace::{Backtrace, BacktraceStatus}; + + if let Some(bt) = std::error::request_ref::(self.0) { + // Hack for testing purposes. + // Read the env var could be slow but we short-circuit it in release mode, + // so this should be optimized out in production. + let force_show_backtrace = cfg!(debug_assertions) + && std::env::var("THISERROR_EXT_TEST_SHOW_USELESS_BACKTRACE").is_ok(); + + // If the backtrace is disabled or unsupported, behave as if there's no backtrace. + if bt.status() == BacktraceStatus::Captured || force_show_backtrace { + // The alternate mode contains a trailing newline while non-alternate + // mode does not. So we need to add a newline before the backtrace. + if !f.alternate() { + writeln!(f)?; + } + writeln!(f, "\nBacktrace:\n{}", bt)?; } - writeln!(f, "\nBacktrace:\n{}", bt)?; } } diff --git a/tests/arc_new_type.rs b/tests/arc_new_type.rs index 29ab1bd..1778316 100644 --- a/tests/arc_new_type.rs +++ b/tests/arc_new_type.rs @@ -1,4 +1,4 @@ -#![feature(error_generic_member_access)] +#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] use std::{error::Error, num::ParseIntError}; diff --git a/tests/backtrace.rs b/tests/backtrace.rs index dbab489..adce7b1 100644 --- a/tests/backtrace.rs +++ b/tests/backtrace.rs @@ -1,3 +1,4 @@ +#![cfg(feature = "backtrace")] #![feature(error_generic_member_access)] use std::backtrace::Backtrace; diff --git a/tests/basic.rs b/tests/basic.rs index 9f85957..33dc904 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,5 +1,6 @@ -// #![feature(error_generic_member_access)] +#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] +#[cfg(feature = "backtrace")] use std::backtrace::Backtrace; use thiserror::*; use thiserror_ext::*; @@ -27,6 +28,7 @@ pub enum MyErrorInner { ParseWithBacktrace { #[source] error: std::num::ParseIntError, + #[cfg(feature = "backtrace")] backtrace: Backtrace, }, @@ -34,6 +36,7 @@ pub enum MyErrorInner { ParseWithBacktraceAndContext { #[source] error: std::num::ParseIntError, + #[cfg(feature = "backtrace")] backtrace: Backtrace, from: String, }, diff --git a/tests/context_into.rs b/tests/context_into.rs index 51bbbb1..fa383be 100644 --- a/tests/context_into.rs +++ b/tests/context_into.rs @@ -1,7 +1,7 @@ //! This example demonstrates how to achieve the similar functionality as //! [`anyhow::Context`] with `thiserror_ext`, in a type-safer manner. -#![feature(error_generic_member_access)] +#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] use expect_test::expect; use thiserror::Error; diff --git a/tests/macro.rs b/tests/macro.rs index 3eac6a6..6fce856 100644 --- a/tests/macro.rs +++ b/tests/macro.rs @@ -1,4 +1,4 @@ -#![feature(error_generic_member_access)] +#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] pub mod inner { use thiserror::Error; diff --git a/tests/report.rs b/tests/report.rs index 55c1f25..39c4508 100644 --- a/tests/report.rs +++ b/tests/report.rs @@ -1,4 +1,4 @@ -#![feature(error_generic_member_access)] +#![cfg(feature = "backtrace")] use expect_test::expect; use sealed_test::prelude::*; diff --git a/tests/report_debug.rs b/tests/report_debug.rs index d539a29..ad4b60f 100644 --- a/tests/report_debug.rs +++ b/tests/report_debug.rs @@ -1,4 +1,4 @@ -#![feature(error_generic_member_access)] +#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] use thiserror::Error; use thiserror_ext::{Box, ReportDebug}; From d476f977dc11a746a4364bd91cbb43c8aa783467 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 13:43:31 +0800 Subject: [PATCH 3/9] fix compiling Signed-off-by: Bugen Zhao --- src/backtrace.rs | 1 + tests/basic.rs | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/backtrace.rs b/src/backtrace.rs index 7391ea8..761776b 100644 --- a/src/backtrace.rs +++ b/src/backtrace.rs @@ -23,6 +23,7 @@ impl WithBacktrace for NoExtraBacktrace { #[cfg(feature = "backtrace")] mod maybe { + use super::WithBacktrace; use std::backtrace::Backtrace; /// Capture backtrace if the error does not already have one. diff --git a/tests/basic.rs b/tests/basic.rs index 33dc904..1a8d301 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -24,23 +24,6 @@ pub enum MyErrorInner { #[error("cannot parse int")] ParseUnnamed(#[source] std::num::ParseFloatError, String), - #[error("cannot parse int")] - ParseWithBacktrace { - #[source] - error: std::num::ParseIntError, - #[cfg(feature = "backtrace")] - backtrace: Backtrace, - }, - - #[error("cannot parse int from `{from}`")] - ParseWithBacktraceAndContext { - #[source] - error: std::num::ParseIntError, - #[cfg(feature = "backtrace")] - backtrace: Backtrace, - from: String, - }, - #[error(transparent)] IoTransparent(std::io::Error), @@ -58,5 +41,25 @@ impl MyError { } } +#[cfg(feature = "backtrace")] +#[derive(Error, Debug, Construct, ContextInto, Box)] +#[thiserror_ext(newtype(name = MyErrorBacktrace))] +pub enum MyErrorBacktraceInner { + #[error("cannot parse int")] + ParseWithBacktrace { + #[source] + error: std::num::ParseIntError, + backtrace: Backtrace, + }, + + #[error("cannot parse int from `{from}`")] + ParseWithBacktraceAndContext { + #[source] + error: std::num::ParseIntError, + backtrace: Backtrace, + from: String, + }, +} + #[test] fn test() {} From f29650694aed15a9b351c20ef98f54b3542267a1 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 13:50:23 +0800 Subject: [PATCH 4/9] test both features Signed-off-by: Bugen Zhao --- .github/workflows/check-test.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index c8e11b1..f3e554f 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -12,16 +12,21 @@ env: jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + toolchain: ["1.77", "nightly-2023-12-26"] steps: - uses: actions/checkout@v3 + - name: Override Rust toolchain + run: rustup override set ${{ matrix.toolchain }} - name: Add Rust components run: rustup component add rustfmt clippy - name: Format run: cargo fmt --check - name: Build - run: cargo build --all-targets --all-features + run: cargo build --all-targets ${{ matrix.toolchain.contains('nightly') && '--all-features' }} - name: Clippy - run: cargo clippy --all-targets --all-features + run: cargo clippy --all-targets ${{ matrix.toolchain.contains('nightly') && '--all-features' }} - name: Run tests - run: cargo test + run: cargo test --all-targets ${{ matrix.toolchain.contains('nightly') && '--all-features' }} From e8cfb4f11f4f46e858bfe76b3ef48a82c0a3dcc6 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 14:02:02 +0800 Subject: [PATCH 5/9] update workflow Signed-off-by: Bugen Zhao --- .github/workflows/check-test.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index f3e554f..a46d415 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -14,7 +14,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - toolchain: ["1.77", "nightly-2023-12-26"] + include: + - toolchain: "1.77" + features: "" + - toolchain: "nightly-2023-12-26" + features: "backtrace" steps: - uses: actions/checkout@v3 @@ -25,8 +29,8 @@ jobs: - name: Format run: cargo fmt --check - name: Build - run: cargo build --all-targets ${{ matrix.toolchain.contains('nightly') && '--all-features' }} + run: cargo build --all-targets --features ${{ matrix.features }} - name: Clippy - run: cargo clippy --all-targets ${{ matrix.toolchain.contains('nightly') && '--all-features' }} + run: cargo clippy --all-targets --features ${{ matrix.features }} - name: Run tests - run: cargo test --all-targets ${{ matrix.toolchain.contains('nightly') && '--all-features' }} + run: cargo test --all-targets --features ${{ matrix.features }} From c8d26f4766f1585fe142627ac3f7c6de7b796dd6 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 14:04:47 +0800 Subject: [PATCH 6/9] fix tet and workflow Signed-off-by: Bugen Zhao --- .github/workflows/check-test.yaml | 8 ++++---- tests/report.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index a46d415..81d0ad1 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -18,7 +18,7 @@ jobs: - toolchain: "1.77" features: "" - toolchain: "nightly-2023-12-26" - features: "backtrace" + features: "--features backtrace" steps: - uses: actions/checkout@v3 @@ -29,8 +29,8 @@ jobs: - name: Format run: cargo fmt --check - name: Build - run: cargo build --all-targets --features ${{ matrix.features }} + run: cargo build --all-targets ${{ matrix.features }} - name: Clippy - run: cargo clippy --all-targets --features ${{ matrix.features }} + run: cargo clippy --all-targets ${{ matrix.features }} - name: Run tests - run: cargo test --all-targets --features ${{ matrix.features }} + run: cargo test --all-targets ${{ matrix.features }} diff --git a/tests/report.rs b/tests/report.rs index 39c4508..41eaf4f 100644 --- a/tests/report.rs +++ b/tests/report.rs @@ -1,4 +1,5 @@ #![cfg(feature = "backtrace")] +#![feature(error_generic_member_access)] use expect_test::expect; use sealed_test::prelude::*; From d5126af762668358face6812a9a81f0fbd7014e8 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 14:09:30 +0800 Subject: [PATCH 7/9] refine workflow again Signed-off-by: Bugen Zhao --- .github/workflows/check-test.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index 81d0ad1..0a69e8a 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -31,6 +31,8 @@ jobs: - name: Build run: cargo build --all-targets ${{ matrix.features }} - name: Clippy - run: cargo clippy --all-targets ${{ matrix.features }} + run: cargo clippy ${{ matrix.features }} -- -D warnings - name: Run tests - run: cargo test --all-targets ${{ matrix.features }} + run: cargo test ${{ matrix.features }} + - name: Generate docs + run: RUSTDOCFLAGS="-Dwarnings" cargo doc --no-deps From 27d645e4badb6c632f85e5f1024508bb9f0b9bd5 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 14:13:43 +0800 Subject: [PATCH 8/9] use nightly toolchain by default Signed-off-by: Bugen Zhao --- .vscode/settings.json | 3 +++ rust-toolchain.toml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..39a5ca1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.cargo.features": "all" +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index fcc85b9..b986b0b 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.77" +channel = "nightly-2023-12-26" From fd7f099051b0d3eeb817bdf6668f0963eb3a5a0d Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 26 Apr 2024 14:23:22 +0800 Subject: [PATCH 9/9] ignore doctests Signed-off-by: Bugen Zhao --- .github/workflows/check-test.yaml | 4 ++-- derive/src/lib.rs | 14 +++++++------- src/report.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index 0a69e8a..ea2b929 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -33,6 +33,6 @@ jobs: - name: Clippy run: cargo clippy ${{ matrix.features }} -- -D warnings - name: Run tests - run: cargo test ${{ matrix.features }} + run: cargo test --workspace ${{ matrix.features }} - name: Generate docs - run: RUSTDOCFLAGS="-Dwarnings" cargo doc --no-deps + run: RUSTDOCFLAGS="-Dwarnings --cfg docsrs" cargo doc --no-deps diff --git a/derive/src/lib.rs b/derive/src/lib.rs index a7432f7..118f834 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -17,7 +17,7 @@ mod thiserror; /// /// # Example /// -/// ```no_run +/// ```ignore /// #[derive(Debug, thiserror::Error, thiserror_ext::Construct)] /// enum Error { /// #[error("unsupported feature: {0}")] @@ -65,7 +65,7 @@ pub fn derive_construct(input: TokenStream) -> TokenStream { /// /// # Example /// -/// ```no_run +/// ```ignore /// #[derive(Debug, thiserror::Error, thiserror_ext::ContextInto)] /// enum Error { /// #[error("cannot parse int from `{from}`")] @@ -126,7 +126,7 @@ pub fn derive_context_into(input: TokenStream) -> TokenStream { /// /// ## Example /// -/// ```no_run +/// ```ignore /// #[derive(Debug, thiserror::Error, thiserror_ext::Macro)] /// enum Error { /// #[error("internal error: {msg}")] @@ -151,7 +151,7 @@ pub fn derive_context_into(input: TokenStream) -> TokenStream { /// /// ## Example /// -/// ```no_run +/// ```ignore /// #[derive(Debug, thiserror::Error, thiserror_ext::Macro)] /// #[error("not yet implemented: {message}")] /// struct NotYetImplemented { @@ -221,7 +221,7 @@ pub fn derive_macro(input: TokenStream) -> TokenStream { /// /// ## Example /// -/// ```no_run +/// ```ignore /// #[derive(Debug, thiserror::Error, thiserror_ext::Box)] /// #[thiserror_ext(newtype(name = Error))] /// enum ErrorKind { @@ -258,7 +258,7 @@ pub fn derive_macro(input: TokenStream) -> TokenStream { /// /// ## Example /// -/// ```no_run +/// ```ignore /// # use std::backtrace::Backtrace; /// #[derive(Debug, thiserror::Error, thiserror_ext::Box)] /// #[thiserror_ext(newtype(name = Error, backtrace))] @@ -312,7 +312,7 @@ pub fn derive_arc(input: TokenStream) -> TokenStream { /// chain can be kept in these cases. /// /// # Example -/// ```no_run +/// ```ignore /// #[derive(thiserror::Error, thiserror_ext::ReportDebug)] /// #[error("inner")] /// struct Inner; diff --git a/src/report.rs b/src/report.rs index 0d0373e..991141d 100644 --- a/src/report.rs +++ b/src/report.rs @@ -29,8 +29,8 @@ pub trait AsReport: crate::error_sealed::Sealed { /// like under different options. /// /// # Example - /// ```no_run - /// use thiserror::AsReport; + /// ```ignore + /// use thiserror_ext::AsReport; /// /// let error = fallible_action().unwrap_err(); /// println!("{}", error.as_report());