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

Crate does no longer work with no-std on 0.7 #82

Closed
Luro02 opened this issue Sep 12, 2021 · 3 comments
Closed

Crate does no longer work with no-std on 0.7 #82

Luro02 opened this issue Sep 12, 2021 · 3 comments

Comments

@Luro02
Copy link

Luro02 commented Sep 12, 2021

It fails with:

error[E0433]: failed to resolve: could not find `std` in the list of imported crates
  --> src\sanitizers\deduplicator.rs:74:9
   |
74 |         assert_eq!(iter.next(), Some('1'));
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `std` in the list of imported crates
   |
   = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

(feature gating every single test with the std feature would be really annoying, especially when the std feature is disabled by default)

The macro expands in 0.7 to something like this:

{
    match (&(sanitizer.next()), &(None)) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                {
                    ::std::rt::begin_panic_fmt(&match match (
                        &::pretty_assertions::Comparison::new(left_val, right_val),
                    ) {
                        (arg0,) => [::core::fmt::ArgumentV1::new(
                            arg0,
                            ::core::fmt::Display::fmt,
                        )],
                    } {
                        ref args => unsafe {
                            ::core::fmt::Arguments::new_v1(
                                &["assertion failed: `(left == right)`\n\n", "\n"],
                                args,
                            )
                        },
                    })
                }
            }
        }
    }
};

Previously (0.6), it expanded to

{
    match (&(sanitizer.next()), &(None)) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                ::core::panicking::panic_fmt(
                    match match (&::pretty_assertions::Comparison::new(
                        left_val, right_val,
                    ),)
                    {
                        (arg0,) => [::core::fmt::ArgumentV1::new(
                            arg0,
                            ::core::fmt::Display::fmt,
                        )],
                    } {
                        ref args => unsafe {
                            ::core::fmt::Arguments::new_v1(
                                &["assertion failed: `(left == right)`\n\n", "\n"],
                                args,
                            )
                        },
                    },
                )
            }
        }
    }
};

Related issue: KokaKiwi/rust-hex#63

@tommilligan
Copy link
Collaborator

Hey, thanks for the report. I've put together a PR which I think should provide no_std support, as long as you still have an allocator: #83

I don't have masses of experience with no_std support - if you could verify this fix works for your use case, I'll be able to merge and release it faster. You can try out the patch with something like:

pretty_assertions = { git="https://github.com/tommilligan/rust-pretty-assertions", rev="9ba9e84d930493f0218615919ec3868c6d36f47b" }

@Luro02
Copy link
Author

Luro02 commented Sep 12, 2021

Thank you, this does work as expected

@tommilligan
Copy link
Collaborator

Closed as released in v1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants