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

False positive for unused_parens in a return #131989

Closed
kawadakk opened this issue Oct 21, 2024 · 1 comment · Fixed by #132936
Closed

False positive for unused_parens in a return #131989

kawadakk opened this issue Oct 21, 2024 · 1 comment · Fixed by #132936
Assignees
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-false-positive Lint: False positive (should not have fired). L-unused_parens Lint: unused_parens T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kawadakk
Copy link
Contributor

kawadakk commented Oct 21, 2024

Code

fn foo() {
    return (_ = 42);
}

Current output

warning: unnecessary parentheses around `return` value
 --> src/lib.rs:2:12
  |
2 |     return (_ = 42);
  |            ^      ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 -     return (_ = 42);
2 +     return _ = 42;
  |

Desired output

No output, since removing the parentheses results in a compile error:

error: expected one of `;`, `}`, or an operator, found reserved identifier `_`
 --> src/lib.rs:2:12
  |
2 |     return _ = 42;
  |            ^ expected one of `;`, `}`, or an operator

Rationale and extra context

No response

Other cases

No response

Rust Version

$ rustc -vV
rustc 1.84.0-nightly (662180b34 2024-10-20)
binary: rustc
commit-hash: 662180b34d95f72d05b7c467b0baf4d23d36b1e1
commit-date: 2024-10-20
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Anything else?

No response

@kawadakk kawadakk 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 21, 2024
@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_parens Lint: unused_parens L-false-positive Lint: False positive (should not have fired). labels Oct 21, 2024
@surechen
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 15, 2024
For expr `return (_ = 42);` unused_paren lint should not be triggered

fixes rust-lang#131989
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 15, 2024
For expr `return (_ = 42);` unused_paren lint should not be triggered

fixes rust-lang#131989
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 15, 2024
For expr `return (_ = 42);` unused_paren lint should not be triggered

fixes rust-lang#131989
@bors bors closed this as completed in 33d3c27 Nov 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 16, 2024
Rollup merge of rust-lang#132936 - surechen:fix_131989, r=Nadrieril

For expr `return (_ = 42);` unused_paren lint should not be triggered

fixes rust-lang#131989
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-false-positive Lint: False positive (should not have fired). 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