Skip to content

Incorrect 'struct is never constructed' warning #59003

Closed
@ejpbruel2

Description

@ejpbruel2

Consider the following code snippet:

struct Foo {
    inner: u32,
}

impl From<u32> for Foo {
    fn from(inner: u32) -> Self {
        Self {
            inner
        }
    }
}

This will trigger a 'struct is never constructed' warning, even though the struct is clearly constructed in the implementation of From<u32>.

The problem seems to be caused by using Self as the constructor. If I replace Self with the name of the struct, as in the following code snippet, the warning goes away:

struct Foo {
    inner: u32,
}

impl From<u32> for Foo {
    fn from(inner: u32) -> Self {
        Foo {
            inner
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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