Repository: Peternator7/strum (rust)

Issue:
strum-macros 0.26.3 breaks `no_std` build
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`:

```rust
#![no_std]

#[derive(strum::Display)]
enum Foo {
    Bar
}

fn main() {
}
```

Sample `Cargo.toml`:

```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.



Pull request description:
Fix the unconditional usage of string interpolation in strum
fixes #359 

Patch:
diff --git a/strum_macros/src/macros/strings/display.rs b/strum_macros/src/macros/strings/display.rs
index 650e5b2..5e7a422 100644
--- a/strum_macros/src/macros/strings/display.rs
+++ b/strum_macros/src/macros/strings/display.rs
@@ -124,7 +124,17 @@ pub fn display_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
                         }
                     }
                 }
-                Fields::Unit => quote! { #name::#ident #params => ::core::fmt::Display::fmt(&format!(#output), f) }
+                Fields::Unit => {
+                    let used_vars = capture_format_strings(&output)?;
+                    if !used_vars.is_empty() {
+                        return Err(syn::Error::new_spanned(
+                            &output,
+                            "Unit variants do not support interpolation",
+                        ));
+                    }
+
+                    quote! { #name::#ident #params => ::core::fmt::Display::fmt(#output, f) }
+                }
             };
 
             arms.push(arm);


Test patch:
diff --git a/strum_nostd_tests/src/lib.rs b/strum_nostd_tests/src/lib.rs
index 816c073..251fe03 100644
--- a/strum_nostd_tests/src/lib.rs
+++ b/strum_nostd_tests/src/lib.rs
@@ -5,7 +5,7 @@ mod tests {
     use core::str::FromStr;
     use strum::EnumString;
 
-    #[derive(Debug, Eq, PartialEq, EnumString)]
+    #[derive(Debug, Eq, PartialEq, EnumString, strum::Display)]
     enum Color {
         Red,
         Blue {