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

unnecessary parentheses warning triggers for necessary parentheses around yield expression #74883

Closed
Nemo157 opened this issue Jul 28, 2020 · 2 comments · Fixed by #75031
Closed
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-coroutines `#![feature(coroutines)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Jul 28, 2020

I tried this code:

#![feature(generator_trait)]
#![feature(generators)]

use std::ops::Generator;

fn main() {
    let mut x = |_| {
        while let Some(val) = (yield) {
            dbg!(val);
        }
    };
    dbg!(std::pin::Pin::new(&mut x).resume(Some(5)));
    dbg!(std::pin::Pin::new(&mut x).resume(Some(6)));
    dbg!(std::pin::Pin::new(&mut x).resume(None));
}

I expected to see this happen: no warning

Instead, this happened:

warning: unnecessary parentheses around `let` scrutinee expression
 --> src/main.rs:8:31
  |
8 |         while let Some(val) = (yield) {
  |                               ^^^^^^^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default

if I follow the suggestion, then compilation fails:

error: expected `{`, found `}`
  --> src/main.rs:11:5
   |
11 |     };
   |     ^ expected `{`

(yield takes an optional expression, not wrapping it in parentheses means the while let block becomes that expression, and the while let is then missing a block).

Meta

  • clippy 0.0.212 (2020-07-27 76e8333)
  • `rustc 1.47.0-nightly (2020-07-27 76e8333)
@flip1995
Copy link
Member

The unused_parens lint is a rustc lint, not a Clippy lint. This issue should probably be moved to the rust-lang/rust repo. @Manishearth can you move this issue, please?

@Manishearth Manishearth transferred this issue from rust-lang/rust-clippy Jul 28, 2020
@Manishearth
Copy link
Member

Done, thanks

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. F-coroutines `#![feature(coroutines)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 28, 2020
@JohnTitor JohnTitor added the C-bug Category: This is a bug. label Jul 28, 2020
@bors bors closed this as completed in db3e10f Aug 2, 2020
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-bug Category: This is a bug. F-coroutines `#![feature(coroutines)]` requires-nightly This issue requires a nightly compiler in some way. 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.

5 participants