Skip to content

unused_assignments false positive in async blocks #84292

Closed
@Kestrer

Description

@Kestrer

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.

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions