Skip to content

Commit 87ee15e

Browse files
authored
Merge branch 'master' into fix-nightly-backtraces
2 parents dd05aa3 + dded7de commit 87ee15e

File tree

8 files changed

+33
-119
lines changed

8 files changed

+33
-119
lines changed

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ jobs:
135135
- uses: actions-rs/cargo@v1
136136
with:
137137
command: clippy
138-
args: --all-targets --all-features -- -D warnings
139-
138+
args: --all-targets --all-features -- -D clippy::style -D clippy::suspicious -D clippy::complexity
140139
miri:
141140
name: Miri
142141
runs-on: ubuntu-latest

color-eyre/src/config.rs

-33
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,6 @@ use std::env;
1111
use std::fmt::Write as _;
1212
use std::{fmt, path::PathBuf, sync::Arc};
1313

14-
#[derive(Debug)]
15-
struct InstallError;
16-
17-
impl fmt::Display for InstallError {
18-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19-
f.write_str("could not install the BacktracePrinter as another was already installed")
20-
}
21-
}
22-
23-
impl std::error::Error for InstallError {}
24-
25-
#[derive(Debug)]
26-
struct InstallThemeError;
27-
28-
impl fmt::Display for InstallThemeError {
29-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30-
f.write_str("could not set the provided `Theme` globally as another was already set")
31-
}
32-
}
33-
34-
impl std::error::Error for InstallThemeError {}
35-
36-
#[derive(Debug)]
37-
struct InstallColorSpantraceThemeError;
38-
39-
impl fmt::Display for InstallColorSpantraceThemeError {
40-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41-
f.write_str("could not set the provided `Theme` via `color_spantrace::set_theme` globally as another was already set")
42-
}
43-
}
44-
45-
impl std::error::Error for InstallColorSpantraceThemeError {}
46-
4714
/// A struct that represents a theme that is used by `color_eyre`
4815
#[derive(Debug, Copy, Clone, Default)]
4916
pub struct Theme {

color-eyre/src/writers.rs

+8
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ impl<W> WriterExt for W {
2828
}
2929
}
3030

31+
#[cfg(feature = "issue-url")]
3132
pub(crate) trait DisplayExt: Sized + Display {
3233
fn with_header<H: Display>(self, header: H) -> Header<Self, H>;
3334
fn with_footer<F: Display>(self, footer: F) -> Footer<Self, F>;
3435
}
3536

37+
#[cfg(feature = "issue-url")]
3638
impl<T> DisplayExt for T
3739
where
3840
T: Display,
@@ -80,11 +82,13 @@ where
8082
}
8183
}
8284

85+
#[cfg(feature = "issue-url")]
8386
pub(crate) struct FooterWriter<W> {
8487
inner: W,
8588
had_output: bool,
8689
}
8790

91+
#[cfg(feature = "issue-url")]
8892
impl<W> fmt::Write for FooterWriter<W>
8993
where
9094
W: fmt::Write,
@@ -98,6 +102,7 @@ where
98102
}
99103
}
100104

105+
#[cfg(feature = "issue-url")]
101106
#[allow(explicit_outlives_requirements)]
102107
pub(crate) struct Footer<B, H>
103108
where
@@ -108,6 +113,7 @@ where
108113
footer: H,
109114
}
110115

116+
#[cfg(feature = "issue-url")]
111117
impl<B, H> fmt::Display for Footer<B, H>
112118
where
113119
B: Display,
@@ -129,6 +135,7 @@ where
129135
}
130136
}
131137

138+
#[cfg(feature = "issue-url")]
132139
#[allow(explicit_outlives_requirements)]
133140
pub(crate) struct Header<B, H>
134141
where
@@ -139,6 +146,7 @@ where
139146
h: H,
140147
}
141148

149+
#[cfg(feature = "issue-url")]
142150
impl<B, H> fmt::Display for Header<B, H>
143151
where
144152
B: Display,

color-eyre/tests/theme.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ fn test_backwards_compatibility(target: String, file_name: &str) {
170170
fn normalize_backtrace(input: &str) -> String {
171171
input
172172
.lines()
173-
.take_while(|v| !v.contains("core::panic") && !v.contains("theme_test_helper::main"))
173+
.take_while(|v| {
174+
!v.contains("core::panic")
175+
&& !v.contains("theme_test_helper::main")
176+
&& !v.contains("theme::test_error_backwards_compatibility::closure")
177+
&& !v.contains("theme::test_error_backwards_compatibility::{{closure}}")
178+
})
174179
.collect::<Vec<_>>()
175180
.join("\n")
176181
}

eyre/src/context.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,34 @@ where
5858
Err(e) => Err(e.ext_report(msg())),
5959
}
6060
}
61+
}
6162

62-
#[cfg(feature = "anyhow")]
63-
fn context<D>(self, msg: D) -> Result<T, Report>
63+
#[cfg(feature = "anyhow")]
64+
impl<T, E> crate::ContextCompat<T> for Result<T, E>
65+
where
66+
Self: WrapErr<T, E>,
67+
{
68+
#[track_caller]
69+
fn context<D>(self, msg: D) -> crate::Result<T, Report>
6470
where
6571
D: Display + Send + Sync + 'static,
6672
{
6773
self.wrap_err(msg)
6874
}
6975

70-
#[cfg(feature = "anyhow")]
71-
fn with_context<D, F>(self, msg: F) -> Result<T, Report>
76+
#[track_caller]
77+
fn with_context<D, F>(self, f: F) -> crate::Result<T, Report>
7278
where
7379
D: Display + Send + Sync + 'static,
7480
F: FnOnce() -> D,
7581
{
76-
self.wrap_err_with(msg)
82+
self.wrap_err_with(f)
7783
}
7884
}
7985

8086
#[cfg(feature = "anyhow")]
8187
impl<T> crate::ContextCompat<T> for Option<T> {
82-
fn wrap_err<D>(self, msg: D) -> Result<T, Report>
83-
where
84-
D: Display + Send + Sync + 'static,
85-
{
86-
self.context(msg)
87-
}
88-
89-
fn wrap_err_with<D, F>(self, msg: F) -> Result<T, Report>
90-
where
91-
D: Display + Send + Sync + 'static,
92-
F: FnOnce() -> D,
93-
{
94-
self.with_context(msg)
95-
}
96-
88+
#[track_caller]
9789
fn context<D>(self, msg: D) -> Result<T, Report>
9890
where
9991
D: Display + Send + Sync + 'static,
@@ -104,6 +96,7 @@ impl<T> crate::ContextCompat<T> for Option<T> {
10496
}
10597
}
10698

99+
#[track_caller]
107100
fn with_context<D, F>(self, msg: F) -> Result<T, Report>
108101
where
109102
D: Display + Send + Sync + 'static,

eyre/src/lib.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ fn capture_handler(error: &(dyn StdError + 'static)) -> Box<dyn EyreHandler> {
624624
}
625625

626626
impl dyn EyreHandler {
627-
/// Returns true if the handler is of the specified type
627+
/// Check if the handler is of type `T`
628628
pub fn is<T: EyreHandler>(&self) -> bool {
629629
// Get `TypeId` of the type this function is instantiated with.
630630
let t = core::any::TypeId::of::<T>();
@@ -1130,21 +1130,6 @@ pub trait WrapErr<T, E>: context::private::Sealed {
11301130
where
11311131
D: Display + Send + Sync + 'static,
11321132
F: FnOnce() -> D;
1133-
1134-
/// Compatibility re-export of wrap_err for interop with `anyhow`
1135-
#[cfg(feature = "anyhow")]
1136-
#[cfg_attr(track_caller, track_caller)]
1137-
fn context<D>(self, msg: D) -> Result<T, Report>
1138-
where
1139-
D: Display + Send + Sync + 'static;
1140-
1141-
/// Compatibility re-export of wrap_err_with for interop with `anyhow`
1142-
#[cfg(feature = "anyhow")]
1143-
#[cfg_attr(track_caller, track_caller)]
1144-
fn with_context<D, F>(self, f: F) -> Result<T, Report>
1145-
where
1146-
D: Display + Send + Sync + 'static,
1147-
F: FnOnce() -> D;
11481133
}
11491134

11501135
/// Provides the [`ok_or_eyre`][OptionExt::ok_or_eyre] method for [`Option`].
@@ -1202,7 +1187,8 @@ pub trait OptionExt<T>: context::private::Sealed {
12021187
M: Debug + Display + Send + Sync + 'static;
12031188
}
12041189

1205-
/// Provides the `context` method for `Option` when porting from `anyhow`
1190+
/// Provides the `context` and `with_context` methods for `Result` and `Option` to enhance
1191+
/// compatibility when porting from anyhow.
12061192
///
12071193
/// This trait is sealed and cannot be implemented for types outside of
12081194
/// `eyre`.
@@ -1261,19 +1247,6 @@ pub trait ContextCompat<T>: context::private::Sealed {
12611247
where
12621248
D: Display + Send + Sync + 'static,
12631249
F: FnOnce() -> D;
1264-
1265-
/// Compatibility re-export of `context` for porting from `anyhow` to `eyre`
1266-
#[cfg_attr(track_caller, track_caller)]
1267-
fn wrap_err<D>(self, msg: D) -> Result<T, Report>
1268-
where
1269-
D: Display + Send + Sync + 'static;
1270-
1271-
/// Compatibility re-export of `with_context` for porting from `anyhow` to `eyre`
1272-
#[cfg_attr(track_caller, track_caller)]
1273-
fn wrap_err_with<D, F>(self, f: F) -> Result<T, Report>
1274-
where
1275-
D: Display + Send + Sync + 'static,
1276-
F: FnOnce() -> D;
12771250
}
12781251

12791252
/// Equivalent to `Ok::<_, eyre::Error>(value)`.

eyre/tests/test_location.rs

+2-32
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn test_context() {
105105
Box::new(LocationHandler::new(expected_location))
106106
}));
107107

108-
use eyre::WrapErr;
108+
use eyre::ContextCompat;
109109
let err = read_path("totally_fake_path")
110110
.context("oopsie")
111111
.unwrap_err();
@@ -122,7 +122,7 @@ fn test_with_context() {
122122
Box::new(LocationHandler::new(expected_location))
123123
}));
124124

125-
use eyre::WrapErr;
125+
use eyre::ContextCompat;
126126
let err = read_path("totally_fake_path")
127127
.with_context(|| "oopsie")
128128
.unwrap_err();
@@ -131,36 +131,6 @@ fn test_with_context() {
131131
println!("{:?}", err);
132132
}
133133

134-
#[cfg(feature = "anyhow")]
135-
#[test]
136-
fn test_option_compat_wrap_err() {
137-
let _ = eyre::set_hook(Box::new(|_e| {
138-
let expected_location = file!();
139-
Box::new(LocationHandler::new(expected_location))
140-
}));
141-
142-
use eyre::ContextCompat;
143-
let err = None::<()>.wrap_err("oopsie").unwrap_err();
144-
145-
// should panic if the location isn't in our crate
146-
println!("{:?}", err);
147-
}
148-
149-
#[cfg(feature = "anyhow")]
150-
#[test]
151-
fn test_option_compat_wrap_err_with() {
152-
let _ = eyre::set_hook(Box::new(|_e| {
153-
let expected_location = file!();
154-
Box::new(LocationHandler::new(expected_location))
155-
}));
156-
157-
use eyre::ContextCompat;
158-
let err = None::<()>.wrap_err_with(|| "oopsie").unwrap_err();
159-
160-
// should panic if the location isn't in our crate
161-
println!("{:?}", err);
162-
}
163-
164134
#[cfg(feature = "anyhow")]
165135
#[test]
166136
fn test_option_compat_context() {

eyre/tests/test_repr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod drop;
44
use self::common::maybe_install_handler;
55
use self::drop::{DetectDrop, Flag};
66
use eyre::Report;
7-
use std::marker::Unpin;
87
use std::mem;
98

109
#[test]

0 commit comments

Comments
 (0)