rust-lang / rust-lang/rust

Cycle detected while trying to transmute future

Open
#124,929 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-cycle S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

use std::mem::MaybeUninit;

fn main() {
    let fut = async {};
    let cast: [MaybeUninit<u8>; 1] = unsafe { std::mem::transmute(fut) };
}

I was playing around and expected this to succeed, instead, it resulted in this:

error[E0391]: cycle detected when type-checking `main`
 --> src/main.rs:3:1
  |
3 | fn main() {
  | ^^^^^^^^^
  |
  = note: ...which requires computing layout of `{async block@src/main.rs:4:15: 4:23}`...
note: ...which requires optimizing MIR for `main::{closure#0}`...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
note: ...which requires elaborating drops for `main::{closure#0}`...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
note: ...which requires coroutine witness types for `main::{closure#0}`...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
note: ...which requires promoting constants in MIR for `main::{closure#0}`...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
note: ...which requires checking if `main::{closure#0}` contains FFI-unwind calls...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
note: ...which requires building MIR for `main::{closure#0}`...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
note: ...which requires match-checking `main::{closure#0}`...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
note: ...which requires type-checking `main::{closure#0}`...
 --> src/main.rs:4:15
  |
4 |     let fut = async {};
  |               ^^^^^^^^
  = note: ...which again requires type-checking `main`, completing the cycle
  = note: cycle used when running analysis passes on this crate
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
Meta

rustc --version --verbose:

rustc 1.80.0-nightly (87293c958 2024-05-08)
binary: rustc
commit-hash: 87293c9585a7fb2cc83ca9949ae79661d5d3c31a
commit-date: 2024-05-08
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

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 example in src/main.rs with the reported rustc 1.80.0-nightly toolchain. Trace the cycle through async-block type checking, layout computation, MIR optimization, drop elaboration, coroutine witness types, and the other queries named in the diagnostic. Done means the reproduction no longer produces the reported cycle or has a clear, appropriate compiler diagnostic.

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
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.