Skip to content

unused_assignments false positive in async blocks #84292

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
Kestrer opened this issue Apr 18, 2021 · 1 comment · Fixed by #84333
Closed

unused_assignments false positive in async blocks #84292

Kestrer opened this issue Apr 18, 2021 · 1 comment · Fixed by #84333
Assignees
Labels
A-async-await Area: Async & Await A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kestrer
Copy link
Contributor

Kestrer commented Apr 18, 2021

In this code:

let mut value = 0;
async {
    value = 1;
    yield_now().await;
    value = 2;
}
.now_or_never();
assert_eq!(value, 1);

The 1 assigned to the value variable is later read. However, Rust incorrectly generates a warning:

warning: value assigned to `value` is never read
 --> src/main.rs:6:9
  |
6 |         value = 1;
  |         ^^^^^
  |
  = note: `#[warn(unused_assignments)]` on by default
  = help: maybe it is overwritten before being read?

Meta

Occurs on both stable 1.51.0 and Nightly 2021-04-17.

rustc --version --verbose:

rustc 1.53.0-nightly (392ba2ba1 2021-04-17)
binary: rustc
commit-hash: 392ba2ba1a7d6c542d2459fb8133bebf62a4a423
commit-date: 2021-04-17
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

This issue has been assigned to @tmiasko via this comment.

@Kestrer Kestrer added the C-bug Category: This is a bug. label Apr 18, 2021
@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 18, 2021
@tmandry
Copy link
Member

tmandry commented Apr 30, 2021

@rustbot assign @tmiasko

@rustbot rustbot self-assigned this Apr 30, 2021
@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Apr 30, 2021
@bors bors closed this as completed in 1a9ac38 Aug 25, 2021
@tmandry tmandry moved this to Done in wg-async work Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants