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

unused_patterns lint #54538

Closed
nikomatsakis opened this issue Sep 24, 2018 · 4 comments · Fixed by #55095
Closed

unused_patterns lint #54538

nikomatsakis opened this issue Sep 24, 2018 · 4 comments · Fixed by #55095
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

As @scottmcm pointed out here, the unused_parens lints should be extended to also catch unused parentheses in patterns:

    match (1) { // Warns, as expected
        (_) => {} // Doesn't warn, but should for consistency
    }

Play

@nikomatsakis nikomatsakis added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. E-needs-mentor labels Sep 24, 2018
@nikomatsakis
Copy link
Contributor Author

Here are some tips for how to update that lint. These aren't full mentoring notes but they might get you started.

The lint itself is declared here:

declare_lint! {
pub(super) UNUSED_PARENS,
Warn,
"`if`, `match`, `while` and `return` do not need parentheses"
}

The meat of it is found in the check_expr callback here, which is invoked for every expression:

fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {

As you can see, it checks for various places where a lint would not be needed, such as in the body if an If, and then invokes this routine check_unused_patterns_core to issue a warning.

For patterns, I imagine we'll want to do something similar, but adding a check_pat method (this is the definition from the trait).

That said, I think this is quite a bit harder than the stabilization itself. If the person who handles this issue wants to do it, seems great, but if they are not familiar with the compiler, I think we could leave it out from the first PR, and then move this to a distinct issue to be added at some later time.

@nikomatsakis nikomatsakis added E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. and removed E-needs-mentor labels Sep 24, 2018
@kleimkuhler
Copy link
Contributor

I can pick this up. The mentoring notes provide enough for me to get started. I will reach out if I need some help or clarification!

@nikomatsakis
Copy link
Contributor Author

@kleimkuhler Great! If you have any further problems, please don't hestitate to ping on Zulip or Discord.

@nikomatsakis
Copy link
Contributor Author

I started a thread on Zulip, for future reference.

Manishearth added a commit to Manishearth/rust that referenced this issue Oct 15, 2018
…erns-lint, r=nikomatsakis

Closes rust-lang#54538: `unused_patterns` lint

Closes rust-lang#54538

r? @nikomatsakis
bors added a commit that referenced this issue Oct 15, 2018
Rollup of 11 pull requests

Successful merges:

 - #54820 (Closes #54538: `unused_patterns` lint)
 - #54963 (Cleanup rustc/session)
 - #54991 (add test for #23189)
 - #55025 (Add missing lifetime fragment specifier to error message.)
 - #55047 (doc: make core::fmt::Error example more simple)
 - #55048 (Don't collect to vectors where unnecessary)
 - #55060 (clarify pointer add/sub function safety concerns)
 - #55062 (Make EvalContext::step public again)
 - #55066 (Fix incorrect link in println! documentation)
 - #55081 (Deduplicate tests)
 - #55088 (Update rustc documentation link)

Failed merges:

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants