Skip to content

Commit 9c5fb56

Browse files
Peternator7Peter Glotfelty
andauthored
Fix warnings in tests from variants that need to exist, but don't get used (#419)
Co-authored-by: Peter Glotfelty <[email protected]>
1 parent 030d7b5 commit 9c5fb56

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

strum_macros/src/macros/strings/as_ref_str.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn as_static_str_inner(
9393
) -> syn::Result<TokenStream> {
9494
let name = &ast.ident;
9595
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
96-
let arms = get_arms(ast, |tok| {
96+
let arms = &get_arms(ast, |tok| {
9797
quote! { ::core::convert::From::from(#tok) }
9898
})?;
9999

@@ -107,8 +107,6 @@ pub fn as_static_str_inner(
107107
parse_quote!('_derivative_strum),
108108
)));
109109
let (impl_generics2, _, _) = generics.split_for_impl();
110-
let arms2 = arms.clone();
111-
let arms3 = arms.clone();
112110

113111
Ok(match trait_variant {
114112
GenerateTraitVariant::AsStaticStr => quote! {
@@ -126,15 +124,15 @@ pub fn as_static_str_inner(
126124
#[inline]
127125
fn from(x: #name #ty_generics) -> &'static str {
128126
match x {
129-
#(#arms2),*
127+
#(#arms),*
130128
}
131129
}
132130
}
133131
impl #impl_generics2 ::core::convert::From<&'_derivative_strum #name #ty_generics> for &'static str #where_clause {
134132
#[inline]
135133
fn from(x: &'_derivative_strum #name #ty_generics) -> &'static str {
136134
match *x {
137-
#(#arms3),*
135+
#(#arms),*
138136
}
139137
}
140138
}
@@ -143,15 +141,15 @@ pub fn as_static_str_inner(
143141
impl #impl_generics #name #ty_generics #where_clause {
144142
pub const fn into_str(&self) -> &'static str {
145143
match self {
146-
#(#arms3),*
144+
#(#arms),*
147145
}
148146
}
149147
}
150148

151149
impl #impl_generics ::core::convert::From<#name #ty_generics> for &'static str #where_clause {
152150
fn from(x: #name #ty_generics) -> &'static str {
153151
match x {
154-
#(#arms2),*
152+
#(#arms),*
155153
}
156154
}
157155
}

strum_tests/tests/as_ref_str.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ fn as_fuchsia_str() {
6464
#[derive(IntoStaticStr)]
6565
enum Foo<'a> {
6666
A,
67+
#[allow(dead_code)]
6768
C(&'a i32),
6869
}
6970

7071
#[derive(IntoStaticStr)]
7172
enum Boo<'a, T> {
7273
A(T),
7374
B,
75+
#[allow(dead_code)]
7476
C(&'a i32),
7577
}
7678

@@ -81,6 +83,7 @@ where
8183
{
8284
A(T),
8385
B,
86+
#[allow(dead_code)]
8487
C(&'a i32),
8588
}
8689

@@ -144,13 +147,15 @@ where
144147
{
145148
A(T),
146149
B,
150+
#[allow(dead_code)]
147151
C(&'a i32),
148152
#[strum(serialize = "Dark")]
149153
D,
150154
#[strum(to_string = "Green")]
151155
G,
152156
#[strum(serialize = "b", to_string = "blue")]
153157
Blue {
158+
#[allow(dead_code)]
154159
hue: usize,
155160
},
156161
#[strum(serialize = "y", serialize = "yellow")]
@@ -161,6 +166,7 @@ where
161166
#[strum(const_into_str)]
162167
enum Baz<'a, T> {
163168
A(T),
169+
#[allow(dead_code)]
164170
C(&'a i32),
165171
}
166172

@@ -170,6 +176,7 @@ enum Baz<'a, T> {
170176
enum BrightnessConst {
171177
DarkBlack,
172178
Dim {
179+
#[allow(dead_code)]
173180
glow: usize,
174181
},
175182
#[strum(serialize = "Bright")]

strum_tests/tests/enum_is.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use strum::EnumIs;
33

44
mod core {} // ensure macros call `::core`
55
#[derive(EnumIs)]
6+
#[allow(dead_code)]
67
enum LifeTimeTest<'a> {
78
One(Cow<'a, str>),
89
Two(&'a str),
910
}
1011
#[derive(EnumIs)]
12+
#[allow(dead_code)]
1113
enum Foo {
1214
Unit,
1315
Named0 {},

strum_tests/tests/enum_variant_table.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use strum::EnumTable;
22

33
#[derive(EnumTable)]
4+
#[allow(dead_code)]
45
enum Color {
56
Red,
67
Yellow,
@@ -15,6 +16,7 @@ enum Color {
1516
// even though this isn't used, it needs to be a test
1617
// because if it doesn't compile, enum variants that conflict with keywords won't work
1718
#[derive(EnumTable)]
19+
#[allow(dead_code)]
1820
enum Keyword {
1921
Const,
2022
}

strum_tests/tests/from_repr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn const_test() {
4444
fn crate_module_path_test() {
4545
pub mod nested {
4646
pub mod module {
47+
#[allow(unused_imports)]
4748
pub use strum;
4849
}
4950
}

0 commit comments

Comments
 (0)