Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ContextCompat consistent and non-ambiguous with WrapErr #150

Merged
merged 8 commits into from
Jun 28, 2024
7 changes: 6 additions & 1 deletion color-eyre/tests/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ fn test_backwards_compatibility(target: String, file_name: &str) {
fn normalize_backtrace(input: &str) -> String {
input
.lines()
.take_while(|v| !v.contains("core::panic") && !v.contains("theme_test_helper::main"))
.take_while(|v| {
!v.contains("core::panic")
&& !v.contains("theme_test_helper::main")
&& !v.contains("theme::test_error_backwards_compatibility::closure")
&& !v.contains("theme::test_error_backwards_compatibility::{{closure}}")
})
.collect::<Vec<_>>()
.join("\n")
}
Expand Down
3 changes: 3 additions & 0 deletions eyre/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
//! [`color-backtrace`]: https://github.com/athre0z/color-backtrace
#![doc(html_root_url = "https://docs.rs/eyre/0.6.11")]
#![cfg_attr(
nightly,

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features track-caller)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features auto-install)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features track-caller)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features auto-install)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Miri

unexpected `cfg` condition name: `nightly`

Check warning on line 333 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Miri

unexpected `cfg` condition name: `nightly`
feature(rustdoc_missing_doc_code_examples),
warn(rustdoc::missing_doc_code_examples)
)]
Expand All @@ -355,8 +355,8 @@
unused_parens,
while_true
)]
#![cfg_attr(backtrace, feature(backtrace))]

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features track-caller)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features auto-install)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features track-caller)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features auto-install)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Miri

unexpected `cfg` condition name: `backtrace`

Check warning on line 358 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Miri

unexpected `cfg` condition name: `backtrace`
#![cfg_attr(doc_cfg, feature(doc_cfg))]

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features track-caller)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features auto-install)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features track-caller)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features auto-install)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Miri

unexpected `cfg` condition name: `doc_cfg`

Check warning on line 359 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Miri

unexpected `cfg` condition name: `doc_cfg`
#![allow(
clippy::needless_doctest_main,
clippy::new_ret_no_self,
Expand Down Expand Up @@ -599,8 +599,8 @@
HOOK.set(hook).map_err(|_| InstallError)
}

#[cfg_attr(track_caller, track_caller)]

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features track-caller)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features auto-install)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features track-caller)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features auto-install)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

unexpected `cfg` condition name: `track_caller`

Check warning on line 602 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Miri

unexpected `cfg` condition name: `track_caller`
#[cfg_attr(not(track_caller), allow(unused_mut))]

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features track-caller)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features --features auto-install)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features track-caller)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features --features auto-install)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

unexpected `cfg` condition name: `track_caller`

Check warning on line 603 in eyre/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

unexpected `cfg` condition name: `track_caller`
fn capture_handler(error: &(dyn StdError + 'static)) -> Box<dyn EyreHandler> {
#[cfg(not(feature = "auto-install"))]
let hook = HOOK
Expand All @@ -624,6 +624,7 @@
}

impl dyn EyreHandler {
/// Check if the handler is of type `T`
pub fn is<T: EyreHandler>(&self) -> bool {
// Get `TypeId` of the type this function is instantiated with.
let t = core::any::TypeId::of::<T>();
Expand All @@ -635,6 +636,7 @@
t == concrete
}

/// Downcast the handler to a contcrete type `T`
pub fn downcast_ref<T: EyreHandler>(&self) -> Option<&T> {
if self.is::<T>() {
unsafe { Some(&*(self as *const dyn EyreHandler as *const T)) }
Expand All @@ -643,6 +645,7 @@
}
}

/// Downcast the handler to a contcrete type `T`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit "concrete"

pub fn downcast_mut<T: EyreHandler>(&mut self) -> Option<&mut T> {
if self.is::<T>() {
unsafe { Some(&mut *(self as *mut dyn EyreHandler as *mut T)) }
Expand Down
2 changes: 0 additions & 2 deletions eyre/tests/test_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ fn test_context() {
Box::new(LocationHandler::new(expected_location))
}));

use eyre::WrapErr;
let err = read_path("totally_fake_path")
.context("oopsie")
.unwrap_err();
Expand All @@ -126,7 +125,6 @@ fn test_with_context() {
Box::new(LocationHandler::new(expected_location))
}));

use eyre::WrapErr;
let err = read_path("totally_fake_path")
.with_context(|| "oopsie")
.unwrap_err();
Expand Down
1 change: 0 additions & 1 deletion eyre/tests/test_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod drop;
use self::common::maybe_install_handler;
use self::drop::{DetectDrop, Flag};
use eyre::Report;
use std::marker::Unpin;
use std::mem;

#[test]
Expand Down
Loading