-
Notifications
You must be signed in to change notification settings - Fork 68
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
[WIP] fix #20 improve test support for no_std
#24
Conversation
Oh my god when you said iirc in no_std eyre doesn't have any way to be constructed from an existing error, it can only be used to construct adhoc error types either via the macros or via I'll go ahead and finish the review now and leave comments, just had to stop for a second to laugh about |
Also someone else opened a PR to do the std -> core change 6 days ago and I missed it / forgot about it, so I'm gonna merge that PR right after it passes tests, so just a heads up you'll need to rebase, I know it's a minor inconvenience but I feel like just closing their PR would be a little rude 😬 |
@@ -342,8 +342,8 @@ mod alloc { | |||
#[cfg(feature = "std")] | |||
pub(crate) use std::boxed::Box; | |||
|
|||
#[cfg(not(feature = "std"))] | |||
pub(crate) use alloc::string::String; | |||
// #[cfg(not(feature = "std"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just remove this rather than commenting it out, and the one below if you can.
@@ -729,6 +730,7 @@ where | |||
unsafe { &mut *(self.vtable.object_mut)(self) } | |||
} | |||
|
|||
#[cfg(feature = "std")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can make this change because this would mean that the Item
type of Chain
changes when we use no_std
mode. This would cause disabling / enabling features to become a breaking change which is a no-go. Did you need the chain interface on no_std? If so we can definitely work something out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the cfg
here because the only usage of the ErrorImpl::chain
function is here: https://github.com/yaahc/eyre/blob/a197feb4e3368f70735a2fe34990fbebb10487cd/src/error.rs#L305-L307 and is marked as std
only. In addition ErrorImpl::chain
is pub crate
making it dead code. It compiles without #[cfg(feature = "std")]
, but clippy rightfully complaints about dead code without this change:
❯ cargo check --no-default-features ⇡!? master
Compiling eyre v0.4.2 (/Users/Matthias/git/rust/eyre)
warning: associated function is never used: `chain`
--> src/error.rs:732:19
|
732 | pub(crate) fn chain(&self) -> Chain<'_> {
| ^^^^^
|
:) sorry I scared you with that typo. Unfortunately I did more research on how to make There seems to be two options:
I tried 2., there are atm 11 doc tests that fail. Wrapping them in For https://github.com/yaahc/eyre/blob/a197feb4e3368f70735a2fe34990fbebb10487cd/src/chain.rs#L21-L40 /// Construct an iterator over a chain of errors via the `source` method
///
#[cfg_attr(feature = "std", doc = r##"
# Example
```rust
use std::error::Error;
use std::fmt::{self, Write};
use eyre::Chain;
use indenter::indented;
fn report(error: &(dyn Error + 'static), f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut errors = Chain::new(error).enumerate();
for (i, error) in errors {
writeln!(f)?;
write!(indented(f).ind(i), "{}", error)?;
}
Ok(())
}
```
"##)] |
I'd prefer option 1, there are ways around the experimental aspect I think, I've done this same thing in tracing and already opened an issue yesterday to use doc_cfg in eyre. |
hey @mattsse, sorry for ignoring this PR for so long, and thank you again for the effort you put into it. I just realized that this PR is no longer something we can merge because I removed support for |
no worries @yaahc, I never quite finished it and then also kinda forgot about it 🙈 |
This PR is part of the work to fix broken tests in
no_std
. (#20)So far ea5a088 includes changes to make eyre compile successfully when
--no-default-feature
is used.Changes made:
std::fmt::Display
withscore::fmt::Display
Chain
structs into singleChain
both forstd
andno_std
. This was necessary because thecrate::chain::Chain
was onlypub(crate)
forno_std
.To fix all the tests for
no_std
is a lot more work, since all the tests usingio::Error
won't work.To add test support
no_std
, I could start with replacing theio::Error
dependent variants in theTestError
with something that supportsno_std
? This could minimize test duplication forno_std
Before I proceed I'd like to get some feedback and I'm happy to hear suggestions.