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

Enum iterators trigger lints which can't be easily silenced #229

Closed
Cerber-Ursi opened this issue Jun 22, 2022 · 2 comments
Closed

Enum iterators trigger lints which can't be easily silenced #229

Cerber-Ursi opened this issue Jun 22, 2022 · 2 comments

Comments

@Cerber-Ursi
Copy link

Consider the following code (from this SO question):

#![warn(
    missing_copy_implementations,
    missing_debug_implementations,
)]

use strum::{Display, EnumIter, EnumString};

macro_rules! define_fruits {
    {$($fruit:ident -> $name:literal),* $(,)?} => {
        #[allow(
            missing_copy_implementations,
            missing_debug_implementations,
        )]
        #[derive(Display, EnumIter, EnumString, Clone, Copy, Debug)]
        pub enum Fruits {
            $(
                // #[strum(to_string = $name)]
                $fruit,
            )*
        }
    };
}

define_fruits! {
    Apple -> "green",
    Orange -> "orange",
}

It triggers both specified warnings, because generated FruitsIter does implement neither Debug nor Copy. The latter is understandable (copyable iterators are quite a footgun, to be honest), the former might probably be adjusted, but maybe this implementation being missing is reasonable too.

What's important, however, is that the user has no way to silence these warnings short of allowing them for the whole module, since there's no way to place the attribute on the derive-generated structure. Probably strum wants to allow these (and possibly others) lints itself?

@Peternator7
Copy link
Owner

Thanks for point this out. Added the linked PR to address the issue. Ideally, the iter should implement debug, but agree that Copy is probably a footgun. Unfortunately adding a Debug impl could be a breaking change b/c someone may have manually implemented it so I'll save that change for a larger version update. We can fix this lint though with a minor change and allowing these 2 lints

@Peternator7
Copy link
Owner

0.24.3 was published 2 weeks ago and silences these errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants