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

Missing "unnecessary parentheses" warning #46137

Closed
leonardo-m opened this issue Nov 20, 2017 · 1 comment
Closed

Missing "unnecessary parentheses" warning #46137

leonardo-m opened this issue Nov 20, 2017 · 1 comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@leonardo-m
Copy link

This program compiles without warnings:

fn main() {
    use std::ops::Range;
    fn foo(r1: Range<u32>, r2: Range<u32>) {
        for _ in r1 {}
        for _ in r2 {}
    }
    foo((0 .. 10), (0 .. 10)); // ***
    foo(0 .. 10, 0 .. 10);
}

I expected a "unnecessary parentheses" warning on the first call to foo() because #[warn(unused_parens)] is on by default.

@TimNN TimNN added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Nov 21, 2017
@zackmdavis
Copy link
Member

This is because we currently don't check for unused parens in call arguments:

let (value, msg, struct_lit_needs_parens) = match e.node {
If(ref cond, ..) => (cond, "`if` condition", true),
While(ref cond, ..) => (cond, "`while` condition", true),
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
WhileLet(_, ref cond, ..) => (cond, "`while let` head expression", true),
ForLoop(_, ref cond, ..) => (cond, "`for` head expression", true),
Match(ref head, _) => (head, "`match` head expression", true),
Ret(Some(ref value)) => (value, "`return` value", false),
Assign(_, ref value) => (value, "assigned value", false),
AssignOp(.., ref value) => (value, "assigned value", false),
InPlace(_, ref value) => (value, "emplacement value", false),
_ => return,
};

(notice: no ast::ExprKind::Call or ::MethodCall in the match).

So another example would be:

fn add_one(n: usize) -> usize {
    n + 1
}

fn main() {
    add_one((2));
}

bors added a commit that referenced this issue Dec 27, 2017
…nthesized_arguments, r=petrochenkov

in which the unused-parens lint comes to cover function and method args

Resolves #46137.
bors added a commit that referenced this issue Jan 20, 2018
…nthesized_arguments, r=petrochenkov

in which the unused-parens lint comes to cover function and method args

Resolves #46137.
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. C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants