rust-lang / rust-lang/rust

Impossible to move type implementing `Copy` into async block without `move` keyword

Open
#155,261 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Note: This is a near-duplicate of my other issue here, but is simpler (no need for closures) and I believe the root cause of that issue. I apologize if I shouldn't have made another issue for this.

Copy types are referenced by default in async blocks instead of moved, making it impossible to move a copy type into an async block without async move, which isn't always desirable.

Example compile failures that I'd expect to succeed (playground):

fn wont_compile_1(input: i32) -> impl Future {
   async {
      input;
   }
}

fn wont_compile_2(input: i32) {
    tokio::task::spawn(async {
        input;
    });
}

In these trivial cases, async move would be an easy fix, but that's not always a viable option. For example, when there's some referenced type that cannot be moved into the block (playground):

use futures::{Stream, StreamExt};

#[derive(Debug, Clone)]
struct Config {}

async fn bad(stream: impl Stream<Item = usize>, config: Config) {
    stream.for_each(|item| async {
        dbg!{item, &config};
    }).await;
}
Workaround

The only workaround I've found is to use a NonCopy newtype:

use std::future::Future;

struct NonCopy(i32);

fn will_compile(input: i32) -> impl Future {
    let input_wrapper = NonCopy(input);
    async {
        let input = input_wrapper;
        input.0;
    }
}
Meta

This happens on Stable, Nightly, and Beta

rustc --version --verbose:

rustc 1.94.1 (e408947bf 2026-03-25)
binary: rustc
commit-hash: e408947bfd200af42db322daf0fadfe7e26d3bd1
commit-date: 2026-03-25
host: x86_64-unknown-linux-gnu
release: 1.94.1
LLVM version: 21.1.8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two minimal async-block examples and the futures StreamExt example on stable, beta, and nightly rustc, using the linked playgrounds. Compare the current diagnostics and behavior with the requested semantics for Copy values and referenced values. Done means the issue has an agreed compiler behavior and corresponding regression coverage, though no repository file or test is named here.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.