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

Fix warnings in tests from variants #419

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions strum_macros/src/macros/strings/as_ref_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn as_static_str_inner(
) -> syn::Result<TokenStream> {
let name = &ast.ident;
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let arms = get_arms(ast, |tok| {
let arms = &get_arms(ast, |tok| {
quote! { ::core::convert::From::from(#tok) }
})?;

Expand All @@ -107,8 +107,6 @@ pub fn as_static_str_inner(
parse_quote!('_derivative_strum),
)));
let (impl_generics2, _, _) = generics.split_for_impl();
let arms2 = arms.clone();
let arms3 = arms.clone();

Ok(match trait_variant {
GenerateTraitVariant::AsStaticStr => quote! {
Expand All @@ -126,15 +124,15 @@ pub fn as_static_str_inner(
#[inline]
fn from(x: #name #ty_generics) -> &'static str {
match x {
#(#arms2),*
#(#arms),*
}
}
}
impl #impl_generics2 ::core::convert::From<&'_derivative_strum #name #ty_generics> for &'static str #where_clause {
#[inline]
fn from(x: &'_derivative_strum #name #ty_generics) -> &'static str {
match *x {
#(#arms3),*
#(#arms),*
}
}
}
Expand All @@ -143,15 +141,15 @@ pub fn as_static_str_inner(
impl #impl_generics #name #ty_generics #where_clause {
pub const fn into_str(&self) -> &'static str {
match self {
#(#arms3),*
#(#arms),*
}
}
}

impl #impl_generics ::core::convert::From<#name #ty_generics> for &'static str #where_clause {
fn from(x: #name #ty_generics) -> &'static str {
match x {
#(#arms2),*
#(#arms),*
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions strum_tests/tests/as_ref_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ fn as_fuchsia_str() {
#[derive(IntoStaticStr)]
enum Foo<'a> {
A,
#[allow(dead_code)]
C(&'a i32),
}

#[derive(IntoStaticStr)]
enum Boo<'a, T> {
A(T),
B,
#[allow(dead_code)]
C(&'a i32),
}

Expand All @@ -81,6 +83,7 @@ where
{
A(T),
B,
#[allow(dead_code)]
C(&'a i32),
}

Expand Down Expand Up @@ -144,13 +147,15 @@ where
{
A(T),
B,
#[allow(dead_code)]
C(&'a i32),
#[strum(serialize = "Dark")]
D,
#[strum(to_string = "Green")]
G,
#[strum(serialize = "b", to_string = "blue")]
Blue {
#[allow(dead_code)]
hue: usize,
},
#[strum(serialize = "y", serialize = "yellow")]
Expand All @@ -161,6 +166,7 @@ where
#[strum(const_into_str)]
enum Baz<'a, T> {
A(T),
#[allow(dead_code)]
C(&'a i32),
}

Expand All @@ -170,6 +176,7 @@ enum Baz<'a, T> {
enum BrightnessConst {
DarkBlack,
Dim {
#[allow(dead_code)]
glow: usize,
},
#[strum(serialize = "Bright")]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use strum::EnumIs;

mod core {} // ensure macros call `::core`
#[derive(EnumIs)]
#[allow(dead_code)]
enum LifeTimeTest<'a> {
One(Cow<'a, str>),
Two(&'a str),
}
#[derive(EnumIs)]
#[allow(dead_code)]
enum Foo {
Unit,
Named0 {},
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_variant_table.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use strum::EnumTable;

#[derive(EnumTable)]
#[allow(dead_code)]
enum Color {
Red,
Yellow,
Expand All @@ -15,6 +16,7 @@ enum Color {
// even though this isn't used, it needs to be a test
// because if it doesn't compile, enum variants that conflict with keywords won't work
#[derive(EnumTable)]
#[allow(dead_code)]
enum Keyword {
Const,
}
Expand Down
1 change: 1 addition & 0 deletions strum_tests/tests/from_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn const_test() {
fn crate_module_path_test() {
pub mod nested {
pub mod module {
#[allow(unused_imports)]
pub use strum;
}
}
Expand Down