Skip to content

tait: "cycle detected when computing type" when using transmute. #98993

Closed
@Dirbaio

Description

@Dirbaio

playground

#![feature(type_alias_impl_trait)]

type Tait = impl Sized;

fn main() {
    let foo1: Tait = 0u32;
    let foo2: Tait = unsafe { core::mem::transmute(foo1) };
}

gives

error[[E0391]](https://doc.rust-lang.org/nightly/error-index.html#E0391): cycle detected when computing type of `Tait::{opaque#0}`
 --> src/main.rs:3:13
  |
3 | type Tait = impl Sized;
  |             ^^^^^^^^^^
  |
note: ...which requires type-checking `main`...
 --> src/main.rs:5:1
  |
5 | fn main() {
  | ^^^^^^^^^
  = note: ...which requires computing layout of `Tait`...
  = note: ...which requires normalizing `Tait`...
  = note: ...which again requires computing type of `Tait::{opaque#0}`, completing the cycle
note: cycle used when checking item types in top-level module
 --> src/main.rs:1:1
  |
1 | / #![feature(type_alias_impl_trait)]
2 | |
3 | | type Tait = impl Sized;
4 | |
... |
7 | |     let foo2: Tait = unsafe { core::mem::transmute(foo1) };
8 | | }
  | |_^

error[[E0512]](https://doc.rust-lang.org/nightly/error-index.html#E0512): cannot transmute between types of different sizes, or dependently-sized types
 --> src/main.rs:7:31
  |
7 |     let foo2: Tait = unsafe { core::mem::transmute(foo1) };
  |                               ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `Tait` does not have a fixed size

I find it quite confusing that the transmute is not allowed. They're the same type after all.

@rustbot label A-impl-trait F-type_alias_impl_trait

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-cycleIssue: A query cycle occurred while none was expectedT-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