Repository: Peternator7/strum
Pull request #287 (2023-07-26 21:00:49)

Fix `EnumIter` macro code generation
close https://github.com/Peternator7/strum/issues/284

I've added test for same kind of mistakes to all trait, let me know if you think it's too much, but at the same time it was quite easy to do.

Peternator7: looks good to me. Thanks for the fix!

Patch:
diff --git a/strum_macros/src/macros/enum_iter.rs b/strum_macros/src/macros/enum_iter.rs
index d136d30..ce8237f 100644
--- a/strum_macros/src/macros/enum_iter.rs
+++ b/strum_macros/src/macros/enum_iter.rs
@@ -80,8 +80,8 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
             marker: ::core::marker::PhantomData #phantom_data,
         }
 
-        impl #impl_generics core::fmt::Debug for #iter_name #ty_generics #where_clause {
-            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        impl #impl_generics ::core::fmt::Debug for #iter_name #ty_generics #where_clause {
+            fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                 // We don't know if the variants implement debug themselves so the only thing we
                 // can really show is how many elements are left.
                 f.debug_struct(#iter_name_debug_struct)


Test patch:
diff --git a/strum_tests/tests/as_ref_no_strum.rs b/strum_tests/tests/as_ref_no_strum.rs
index 82e3adc..e8261f4 100644
--- a/strum_tests/tests/as_ref_no_strum.rs
+++ b/strum_tests/tests/as_ref_no_strum.rs
@@ -1,5 +1,7 @@
 use strum_macros::AsRefStr;
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, AsRefStr)]
 enum Color {
     #[strum(to_string = "RedRed")]
diff --git a/strum_tests/tests/as_ref_str.rs b/strum_tests/tests/as_ref_str.rs
index f6a4321..d492f17 100644
--- a/strum_tests/tests/as_ref_str.rs
+++ b/strum_tests/tests/as_ref_str.rs
@@ -3,6 +3,8 @@
 use std::str::FromStr;
 use strum::{AsRefStr, AsStaticRef, AsStaticStr, EnumString, IntoStaticStr};
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, EnumString, AsRefStr, AsStaticStr, IntoStaticStr)]
 enum Color {
     #[strum(to_string = "RedRed")]
diff --git a/strum_tests/tests/display.rs b/strum_tests/tests/display.rs
index 2e1b996..4cec148 100644
--- a/strum_tests/tests/display.rs
+++ b/strum_tests/tests/display.rs
@@ -1,5 +1,7 @@
 use strum::{Display, EnumString};
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, EnumString, Display)]
 enum Color {
     #[strum(to_string = "RedRed")]
diff --git a/strum_tests/tests/enum_count.rs b/strum_tests/tests/enum_count.rs
index db98110..3e24d63 100644
--- a/strum_tests/tests/enum_count.rs
+++ b/strum_tests/tests/enum_count.rs
@@ -1,5 +1,7 @@
 use strum::{EnumCount, EnumIter, IntoEnumIterator};
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, EnumCount, EnumIter)]
 enum Week {
     Sunday,
diff --git a/strum_tests/tests/enum_discriminants.rs b/strum_tests/tests/enum_discriminants.rs
index 9985f0e..eb29e6d 100644
--- a/strum_tests/tests/enum_discriminants.rs
+++ b/strum_tests/tests/enum_discriminants.rs
@@ -1,6 +1,9 @@
 use enum_variant_type::EnumVariantType;
 use strum::{Display, EnumDiscriminants, EnumIter, EnumMessage, EnumString, IntoEnumIterator};
 
+
+mod core {} // ensure macros call `::core`
+
 #[allow(dead_code)]
 #[derive(Debug, Eq, PartialEq, EnumDiscriminants)]
 #[strum_discriminants(derive(EnumIter))]
diff --git a/strum_tests/tests/enum_is.rs b/strum_tests/tests/enum_is.rs
index 186cb23..789881c 100644
--- a/strum_tests/tests/enum_is.rs
+++ b/strum_tests/tests/enum_is.rs
@@ -1,5 +1,7 @@
 use strum::EnumIs;
 
+mod core {} // ensure macros call `::core`
+
 #[derive(EnumIs)]
 enum Foo {
     Unit,
diff --git a/strum_tests/tests/enum_iter.rs b/strum_tests/tests/enum_iter.rs
index 7468267..313ed5c 100644
--- a/strum_tests/tests/enum_iter.rs
+++ b/strum_tests/tests/enum_iter.rs
@@ -1,5 +1,7 @@
 use strum::{EnumIter, IntoEnumIterator};
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, EnumIter)]
 enum Week {
     Sunday,
diff --git a/strum_tests/tests/enum_message.rs b/strum_tests/tests/enum_message.rs
index a5f7bde..b1c8600 100644
--- a/strum_tests/tests/enum_message.rs
+++ b/strum_tests/tests/enum_message.rs
@@ -1,5 +1,7 @@
 use strum::EnumMessage;
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, EnumMessage)]
 enum Pets {
     // This comment is not collected since it starts with "//" instead of "///".
diff --git a/strum_tests/tests/enum_props.rs b/strum_tests/tests/enum_props.rs
index 68fbb4d..c32c07e 100644
--- a/strum_tests/tests/enum_props.rs
+++ b/strum_tests/tests/enum_props.rs
@@ -1,5 +1,7 @@
 use strum::EnumProperty;
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, EnumProperty)]
 enum Test {
     #[strum(props(key = "value"))]
diff --git a/strum_tests/tests/enum_variant_names.rs b/strum_tests/tests/enum_variant_names.rs
index f2ca98b..afd8e4d 100644
--- a/strum_tests/tests/enum_variant_names.rs
+++ b/strum_tests/tests/enum_variant_names.rs
@@ -1,6 +1,8 @@
 use structopt::StructOpt;
 use strum::{EnumString, EnumVariantNames, VariantNames};
 
+mod core {} // ensure macros call `::core`
+
 #[test]
 fn simple() {
     #[allow(dead_code)]
diff --git a/strum_tests/tests/from_repr.rs b/strum_tests/tests/from_repr.rs
index 403ac5a..4e8f0ec 100644
--- a/strum_tests/tests/from_repr.rs
+++ b/strum_tests/tests/from_repr.rs
@@ -1,5 +1,7 @@
 use strum::FromRepr;
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, FromRepr, PartialEq)]
 /// Day of the week
 #[repr(u8)]
diff --git a/strum_tests/tests/from_str.rs b/strum_tests/tests/from_str.rs
index 845768c..fd71194 100644
--- a/strum_tests/tests/from_str.rs
+++ b/strum_tests/tests/from_str.rs
@@ -1,6 +1,8 @@
 use std::str::FromStr;
 use strum::EnumString;
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, EnumString)]
 enum Color {
     Red,
diff --git a/strum_tests/tests/phf.rs b/strum_tests/tests/phf.rs
index 163418e..da2a854 100644
--- a/strum_tests/tests/phf.rs
+++ b/strum_tests/tests/phf.rs
@@ -1,3 +1,5 @@
+mod core {} // ensure macros call `::core`
+
 #[cfg(feature = "test_phf")]
 #[test]
 fn from_str_with_phf() {
diff --git a/strum_tests/tests/serialize_all.rs b/strum_tests/tests/serialize_all.rs
index b754816..5798fa6 100644
--- a/strum_tests/tests/serialize_all.rs
+++ b/strum_tests/tests/serialize_all.rs
@@ -3,6 +3,8 @@ use std::str::FromStr;
 use std::string::ToString;
 use strum::{Display, EnumString, IntoStaticStr};
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, EnumString, Display, IntoStaticStr)]
 #[strum(serialize_all = "title_case")]
 enum Foo1 {
diff --git a/strum_tests/tests/to_string.rs b/strum_tests/tests/to_string.rs
index 91538fc..c3c2973 100644
--- a/strum_tests/tests/to_string.rs
+++ b/strum_tests/tests/to_string.rs
@@ -4,6 +4,8 @@ use std::str::FromStr;
 use std::string::ToString;
 use strum::{EnumString, ToString};
 
+mod core {} // ensure macros call `::core`
+
 #[derive(Debug, Eq, PartialEq, EnumString, ToString)]
 enum Color {
     #[strum(to_string = "RedRed")]