Skip to content

Cannot use Self to construct a tuple struct in a macro #57523

Closed
@kennytm

Description

@kennytm

Reproduced on both on beta and nightly (not tested on stable since #51994 wasn't stabilized in 1.31).

#![warn(clippy::use_self)]

pub struct S(pub u16);

impl From<u8> for S {
    fn from(a: u8) -> Self {
        Self(a.into())            // <-- this is fine
    }
}

macro_rules! a {
    () => {
        impl From<u16> for S {
            fn from(a: u16) -> Self {
                // S(a)            // <-- this is fine but triggers the `clippy::use_self` warning
                Self(a)            // <-- ERROR E0423
                // Self { 0: a }   // <-- this is fine but ugly
            }
        }
    }
}

a!();

fn main() {}

This is particularly troublesome on nightly since clippy::use_self is recently upgraded to emit the lint in a local macro thanks to rust-lang/rust-clippy#3627, but the suggestion failed to compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions