Skip to content

false positive for unused_parens in a let-else #131655

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

Closed
its-the-shrimp opened this issue Oct 13, 2024 · 2 comments · Fixed by #134034
Closed

false positive for unused_parens in a let-else #131655

its-the-shrimp opened this issue Oct 13, 2024 · 2 comments · Fixed by #134034
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_parens Lint: unused_parens T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@its-the-shrimp
Copy link
Contributor

its-the-shrimp commented Oct 13, 2024

Code

fn main() {
    macro_rules! x {
        () => { None::<i32> };
    }

    let Some(_x) = (x! {}) else { return };
}

Current output

warning: unnecessary parentheses around assigned value
 --> src/main.rs:6:20
  |
6 |     let Some(_x) = (x! {}) else { return };
  |                    ^     ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
6 -     let Some(_x) = (x! {}) else { return };
6 +     let Some(_x) = x! {} else { return };
  |

warning: 1 warning emitted

Desired output

nothing

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.83.0-nightly (6b9676b 2024-10-12)
binary: rustc
commit-hash: 6b9676b
commit-date: 2024-10-12
host: aarch64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.1

Anything else?

This was an issue on a nightly from 7th of August as well

@its-the-shrimp its-the-shrimp added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 13, 2024
@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_parens Lint: unused_parens labels Oct 13, 2024
@ChrisDenton
Copy link
Member

I think it should suggest:

let Some(_x) = x!() else { return };

@its-the-shrimp
Copy link
Contributor Author

I think it should suggest:

let Some(_x) = x!() else { return };

different macros have different implications in regards to what parentheses are to be used with them, it shouldn't be a concern of the compiler

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 1, 2025
handle paren in macro expand for let-init-else expr

Fixes rust-lang#131655

This PR modifies the codegen logic of the macro expansion within `let-init-else` expression:
- Before: The expression `let xxx = (mac! {}) else {}` expands to `let xxx = (expanded_ast) else {}`.
- After: The same expression expands to `let xxx = expanded_ast else {}`.

An alternative solution to this issue could involve handling the source code directly when encountering unused parentheses in `let-init-else` expressions. However, this approach might be more cumbersome due to the absence of the necessary data structure.

r? `@petrochenkov`
Zalathar added a commit to Zalathar/rust that referenced this issue May 1, 2025
handle paren in macro expand for let-init-else expr

Fixes rust-lang#131655

This PR modifies the codegen logic of the macro expansion within `let-init-else` expression:
- Before: The expression `let xxx = (mac! {}) else {}` expands to `let xxx = (expanded_ast) else {}`.
- After: The same expression expands to `let xxx = expanded_ast else {}`.

An alternative solution to this issue could involve handling the source code directly when encountering unused parentheses in `let-init-else` expressions. However, this approach might be more cumbersome due to the absence of the necessary data structure.

r? ``@petrochenkov``
Zalathar added a commit to Zalathar/rust that referenced this issue May 1, 2025
handle paren in macro expand for let-init-else expr

Fixes rust-lang#131655

This PR modifies the codegen logic of the macro expansion within `let-init-else` expression:
- Before: The expression `let xxx = (mac! {}) else {}` expands to `let xxx = (expanded_ast) else {}`.
- After: The same expression expands to `let xxx = expanded_ast else {}`.

An alternative solution to this issue could involve handling the source code directly when encountering unused parentheses in `let-init-else` expressions. However, this approach might be more cumbersome due to the absence of the necessary data structure.

r? ```@petrochenkov```
@bors bors closed this as completed in 96852e2 May 2, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 2, 2025
Rollup merge of rust-lang#134034 - bvanjoi:issue-131655, r=petrochenkov

handle paren in macro expand for let-init-else expr

Fixes rust-lang#131655

This PR modifies the codegen logic of the macro expansion within `let-init-else` expression:
- Before: The expression `let xxx = (mac! {}) else {}` expands to `let xxx = (expanded_ast) else {}`.
- After: The same expression expands to `let xxx = expanded_ast else {}`.

An alternative solution to this issue could involve handling the source code directly when encountering unused parentheses in `let-init-else` expressions. However, this approach might be more cumbersome due to the absence of the necessary data structure.

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_parens Lint: unused_parens 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.

3 participants