Skip to content

false positive on unused_parens lint #26461

Closed
@tomjakubowski

Description

@tomjakubowski
Contributor
fn main() {
    if (return) {}
}

sez:

<anon>:2:8: 2:16 warning: unnecessary parentheses around `if` condition, #[warn(unused_parens)] on by default
<anon>:2     if (return) {}
                ^~~~~~~~

However, removing the parentheses makes the file have illegal syntax, because {} is part of the return expression (so the if is missing its arm).

Activity

tomjakubowski

tomjakubowski commented on Jun 21, 2015

@tomjakubowski
ContributorAuthor

Also, by the way, it's very amusing to me that this is legal:

fn main() {
    if return { return } { return } else { return }
}
samdoiron

samdoiron commented on Nov 26, 2015

@samdoiron

Triage: Warning still generated in nightly build. Seems to be an issue with contains_exterior_struct_lit not identifying return {} as an exterior expression.

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 9, 2017
euclio

euclio commented on Dec 4, 2018

@euclio
Contributor

Looks like this was fixed in #55166, and there's a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@oli-obk@tomjakubowski@euclio@samdoiron

        Issue actions

          false positive on unused_parens lint · Issue #26461 · rust-lang/rust