Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@9SMTM6

Description

@9SMTM6

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions