Skip to content

Commit

Permalink
Fix the unconditional usage of string interpolation in strum (#360)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
  • Loading branch information
Peternator7 and Peter Glotfelty authored Jun 5, 2024
1 parent c89286f commit a663c60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion strum_macros/src/macros/strings/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion strum_nostd_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a663c60

Please sign in to comment.