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

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

Closed
Kimundi opened this issue Aug 1, 2014 · 3 comments
Closed

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

Kimundi opened this issue Aug 1, 2014 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@Kimundi
Copy link
Member

Kimundi commented Aug 1, 2014

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.

@SiegeLord
Copy link
Contributor

Isn't this the same situation as ignoring function returns? To that end, I'd imagine you would simply decorate the two structs with #[must_use].

@Kimundi
Copy link
Member Author

Kimundi commented Aug 2, 2014

@SiegeLord: Well, both structs constructors have no side effects and only exist to return a value. So I guess what I want is something like #[must_use] automatically applied to all of them :P

@steveklabnik steveklabnik added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 27, 2015
@sanxiyn
Copy link
Member

sanxiyn commented Oct 29, 2015

Implemented in Clippy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

4 participants