Skip to content

Consider warning for struct/enum constructors without effect. #16170

Closed
@Kimundi

Description

@Kimundi
struct Warns;
struct WarnsNot1 { a: uint }
struct WarnsNot2(uint);

fn main() {
    Warns;
    WarnsNot1 { a: 0 };
    WarnsNot2(0u);
}

This produces a #[warn(path_statement)] warning for the Warns statement, but not for the WarnsNotX statements.

This is somewhat understandable, as the later two can have side effects as part of evaluating their arguments, and also expected of functions in general.

But it might be useful to have a lint for struct and enum constructors whose result is discarded like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions