Closed
Description
Reproduction:
use tokio::select;
use futures::future;
#[tokio::main]
async fn main() {
let v = async move {
let ok = future::ready(1);
tokio::pin!(ok);
select! {
mut a = &mut ok => {
a += 1;
a
}
}
}.await;
println!("v: {}", v);
}
I expected to see this happen: no warnings.
Instead, this happened:
warning: variable does not need to be mutable
--> src/main.rs:10:13
|
10 | mut a = &mut ok => {
| ----^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` on by default
warning: 1 warning emitted
If I follow the advice here, it fails to compile with:
error[E0384]: cannot assign twice to immutable variable `a`
--> src/main.rs:11:17
|
10 | a = &mut ok => {
| -
| |
| first assignment to `a`
| help: make this binding mutable: `mut a`
11 | a += 1;
| ^^^^^^ cannot assign twice to immutable variable
error: aborting due to previous error
This is possibly related to #60643, but I'm not sure. This one is not in a macro itself, it's using a macro.
Meta
rustc --version --verbose
:
rustc 1.45.0 (5c1f21c3b 2020-07-13)
binary: rustc
commit-hash: 5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2
commit-date: 2020-07-13
host: x86_64-unknown-linux-gnu
release: 1.45.0
LLVM version: 10.0
(but this has been happening on every version I've tried for over a year)