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

Lint potential uses of non_exhaustive #2017

Closed
clarfonthey opened this issue Sep 3, 2017 · 3 comments · Fixed by #5550
Closed

Lint potential uses of non_exhaustive #2017

clarfonthey opened this issue Sep 3, 2017 · 3 comments · Fixed by #5550
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-AST Type: Requires working with the AST

Comments

@clarfonthey
Copy link
Contributor

Once rust-lang/rust#44109 merges, instances like this:

struct Test {
    pub val: u32,
    _priv: (),
}

Can be better worded as:

#[non_exhaustive]
struct Test {
    pub val: u32,
}

Additionally, having a unit variant at the end of an enum which is doc(hidden) should be marked as well.

@oli-obk oli-obk added L-unnecessary Lint: Warn about unnecessary code good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-AST Type: Requires working with the AST labels Sep 4, 2017
@clarfonthey clarfonthey changed the title Lint potential uses of non_exhaustive once feature stabilises Lint potential uses of non_exhaustive Dec 4, 2017
@clarfonthey
Copy link
Contributor Author

This has been implemented upstream, so, I updated the title for the issue

@oli-obk
Copy link
Contributor

oli-obk commented Dec 4, 2017

Do you have a link? When will it become stable?

@Luro02
Copy link

Luro02 commented Mar 24, 2020

This feature became stable with version 1.40 https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html
RFC-2008

bors added a commit that referenced this issue May 1, 2020
Implement the manual_non_exhaustive lint

Some implementation notes:
* Not providing automatic fixups because additional changes may be needed in other parts of the code, e.g. when constructing a struct.
* Even though the attribute is valid on enum variants, it's not possible to use the manual implementation of the pattern because the visibility is always public, so the lint ignores enum variants.
* Unit structs are also ignored, it's not possible to implement the pattern manually without fields.
* The attribute is not accepted in unions, so those are ignored too.
* Even though the original issue did not mention it, tuple structs are also linted because it's possible to apply the pattern manually.

changelog: Added the manual non-exhaustive implementation lint

Closes #2017
@bors bors closed this as completed in cc9088f May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-AST Type: Requires working with the AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants