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

strum-macros 0.26.3 breaks no_std build #359

Closed
tronical opened this issue Jun 2, 2024 · 5 comments · Fixed by #360
Closed

strum-macros 0.26.3 breaks no_std build #359

tronical opened this issue Jun 2, 2024 · 5 comments · Fixed by #360

Comments

@tronical
Copy link

tronical commented Jun 2, 2024

With 0.26.3, the emitted code when using derive(strum::Display) uses format! unconditionally. This requires the surrounding code to use format::alloc;, which seems like an unfortunate breaking change to me.

Example main.rs:

#![no_std]

#[derive(strum::Display)]
enum Foo {
    Bar
}

fn main() {
}

Sample Cargo.toml:

[package]
name = "strumtest"
version = "0.1.0"
edition = "2021"

[dependencies]
strum = { version = "0.26.2", features = ["derive"] }
strum_macros = { version = "0.26.3" }

If you downgrade to =0.26.2 the build works, otherwise it aborts with:

error: cannot find macro `format` in this scope
 --> src/main.rs:3:10
  |
3 | #[derive(strum::Display)]
  |          ^^^^^^^^^^^^^^
  |
  = note: this error originates in the derive macro `strum::Display` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `strumtest` (bin "strumtest") due to 1 previous error

I think it's okay to require the surrounding no_std code to use alloc::format; when using strum, but it would be great if this requirement could come with a new major version (0.27) instead.

@Peternator7
Copy link
Owner

This was unintentional. Thank you for pointing it out, I've put out a candidate fix that I'll merge later today if everything seems correct.

@tronical
Copy link
Author

tronical commented Jun 2, 2024

Thank you!

@gmryuuko
Copy link

gmryuuko commented Jun 3, 2024

This was unintentional. Thank you for pointing it out, I've put out a candidate fix that I'll merge later today if everything seems correct.

Another breaking change is that format! will affect serialize. I have an enum like this:

#[derive(Display)]
enum SyntaxKind {
    #[strum(serialize = "`{`")]
    LCurly,
}

Any serialize containing {} characters will be broken.

@Peternator7
Copy link
Owner

@tronical, 0.26.4 is available that should fix your issue. @gmryuuko, in your case, you can mitigate by escaping the curly brace.

#[derive(Display)]
enum SyntaxKind {
    #[strum(serialize = "`{{`")]
    LCurly,
}

@tronical
Copy link
Author

tronical commented Jun 5, 2024

Thanks a lot!

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

Successfully merging a pull request may close this issue.

3 participants