Skip to content

Commit

Permalink
Fix EnumIter macro code generation (#287)
Browse files Browse the repository at this point in the history
* Add test to ensure macro call `::core`-related functions

Avoiding local core modules to break the macro-generated code.

Currently failing due to issue with `EnumIter` macros.

* Fix macro of `EnumIter`

close #284

---------

Co-authored-by: kraktus <kraktus@users.noreply.github.com>
  • Loading branch information
kraktus and kraktus authored Jul 29, 2023
1 parent 96c63e9 commit fd519ec
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions strum_macros/src/macros/enum_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/as_ref_no_strum.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/as_ref_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/display.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_count.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use strum::{EnumCount, EnumIter, IntoEnumIterator};

mod core {} // ensure macros call `::core`

#[derive(Debug, EnumCount, EnumIter)]
enum Week {
Sunday,
Expand Down
3 changes: 3 additions & 0 deletions strum_tests/tests/enum_discriminants.rs
Original file line number Diff line number Diff line change
@@ -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))]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_is.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use strum::EnumIs;

mod core {} // ensure macros call `::core`

#[derive(EnumIs)]
enum Foo {
Unit,
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_iter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use strum::{EnumIter, IntoEnumIterator};

mod core {} // ensure macros call `::core`

#[derive(Debug, Eq, PartialEq, EnumIter)]
enum Week {
Sunday,
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_message.rs
Original file line number Diff line number Diff line change
@@ -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 "///".
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_props.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use strum::EnumProperty;

mod core {} // ensure macros call `::core`

#[derive(Debug, EnumProperty)]
enum Test {
#[strum(props(key = "value"))]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/enum_variant_names.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames, VariantNames};

mod core {} // ensure macros call `::core`

#[test]
fn simple() {
#[allow(dead_code)]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/from_repr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use strum::FromRepr;

mod core {} // ensure macros call `::core`

#[derive(Debug, FromRepr, PartialEq)]
/// Day of the week
#[repr(u8)]
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/from_str.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/phf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod core {} // ensure macros call `::core`

#[cfg(feature = "test_phf")]
#[test]
fn from_str_with_phf() {
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/serialize_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions strum_tests/tests/to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit fd519ec

Please sign in to comment.