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

let_and_return FP on ugly async Send workaround #8598

Open
ijackson opened this issue Mar 28, 2022 · 0 comments
Open

let_and_return FP on ugly async Send workaround #8598

ijackson opened this issue Mar 28, 2022 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@ijackson
Copy link

Summary

let_and_return trips up on an awful construction I invented to avoid a future-not-Send problem.

The workaround code I have here is terrible, but I'm not aware of a better way to write it. (NB that in this example I use mpc::channel::Receiver as a thing that is Send but not Sync; the example program doesn't make much sense semantically.)

I bet the underlying cause is the same as #8114.

Lint Name

let_and_return

Reproducer

I tried this code:

use std::sync::mpsc;
use std::future::Future;
use std::pin::Pin;

async fn awaitpoint(_: ()) { }

async fn failure() {
    let (_, rx) = mpsc::channel::<()>();

    while let Ok(event) = { let k= &rx; k.recv()} {
        awaitpoint(event).await;
    }
}

fn main() {
    let _: Pin<Box<dyn Future<Output=()> + Send>> = Box::pin(
        async {
            failure().await;
        }
    );
}

I saw this happen:

    Checking foo v0.1.0 (/volatile/rustcargo/Rustup/Arti/experiments)
warning: returning the result of a `let` binding from a block
  --> src/main.rs:10:59
   |
10 |     while let Ok(event) = { let k= &rx; let y = k.recv(); y } {
   |                                         ----------------- ^
   |                                         |
   |                                         unnecessary `let` binding
   |
   = note: `#[warn(clippy::let_and_return)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
help: return the expression directly
   |
10 -     while let Ok(event) = { let k= &rx; let y = k.recv(); y } {
10 +     while let Ok(event) = { let k= &rx;  k.recv() } {
   | 

warning: `foo` (bin "foo") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s

I expected to see this happen:

Well, ideally, Rust would have accepted

    while let Ok(event) = rx.recv() {

but failing that, it wouldl be nice if clippy didn't suggest changes that cause compiler errors.

Version

rustc 1.61.0-nightly (1bfe40d11 2022-03-18)
binary: rustc
commit-hash: 1bfe40d11c3630254504fb73eeccfca28d50df52
commit-date: 2022-03-18
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Additional Labels

@rustbot label +I-suggestion-causes-error

@ijackson ijackson added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 28, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

2 participants