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

Properly propogate attributes to Debug impl, and also add #[automatically_derived] #34

Open
9SMTM6 opened this issue Oct 19, 2024 · 0 comments

Comments

@9SMTM6
Copy link

9SMTM6 commented Oct 19, 2024

I've code that looks something like this:

#[cfg_persistence_derive]
#[derive(Clone)]
#[derive(::educe::Educe)]
#[educe(Debug)
]#[allow(clippy::used_underscore_binding, reason = "Should be educe causing this")]
pub enum ProgressMode {
    Batched { size: IPromiseThisIsNonZeroUsize },
}

if I cargo-expand this, I get:

    #[educe(Debug)]
    #[allow(clippy::used_underscore_binding, reason = "Should be educe causing this")]
    pub enum ProgressMode {
        Batched { size: IPromiseThisIsNonZeroUsize },
    }
    impl ::core::fmt::Debug for ProgressMode
    where
        IPromiseThisIsNonZeroUsize: ::core::fmt::Debug,
    {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            match self {
                Self::Batched { size: _size } => {
                    let mut builder = f.debug_struct("Batched");
                    builder.field("size", _size);
                    builder.finish()
                }
            }
        }
    }
    #[automatically_derived]
    #[allow(clippy::used_underscore_binding, reason = "Should be educe causing this")]
    impl ::core::clone::Clone for ProgressMode {
        #[inline]
        fn clone(&self) -> ProgressMode {
            match self {
                ProgressMode::Batched { size: __self_0 } => {
                    ProgressMode::Batched {
                        size: ::core::clone::Clone::clone(__self_0),
                    }
                }
            }
        }
    }

as you see, #[derive(Clone) correctly propagates the #[allow] attribute, educe did not.

Because of this, and the was the generated code looks (it does prepend an underscore to variables in some situations) I have no nice way to fix errors caused by disallowing clippy::used_underscore_binding. I have not so nice ones, like disabling that lint globally, or defining all this in a separate module where this lint is allowed, but these seem like hotfixes, not the proper solution, to me.

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

1 participant