Skip to content

rustc cannot determine if a type is Sized #154522

@ds84182

Description

@ds84182

I tried this code:

use std::marker::PhantomData;

pub trait ForLt<'a> { type Ty: 'a; }
impl<'a, T: ForLt<'a> + ?Sized> ForLt<'a> for PhantomData<T> {
  type Ty = T::Ty;
}

macro_rules! hkt {
  (for<$lt:lifetime> $T:ty) => {
    ::core::marker::PhantomData<dyn for<$lt> ForLt<$lt, Ty = $T>>
  };
  ($T:ty) => {
    ::core::marker::PhantomData<dyn for<'a> ForLt<'a, Ty = $T>>
  };
}

pub trait ValueLike {}
pub trait Value<'a>: ValueLike {}
pub trait ComposableValue<'a>: ValueLike {}

pub struct Dummy;
impl ValueLike for Dummy {}
impl<'a> Value<'a> for Dummy {}
impl<'a> ComposableValue<'a> for Dummy {}

impl<A: ValueLike, B: ValueLike> ValueLike for (A, B) {}
impl<'a, A: ComposableValue<'a>, B: Value<'a>> Value<'a> for (A, B) {}

pub trait OpenTable {
    type Table;
    fn open() -> Self::Table;
}

pub trait TableDesc {
    type Table;
}

pub struct RocksDbTable<M, K, V> {
  pub(crate) _pd: PhantomData<(M, K, V)>,
}

impl<
  M,
  K: for<'a> ForLt<'a, Ty: Value<'a>>,
  V: for<'a> ForLt<'a, Ty: Value<'a>>,
  T: TableDesc<Table = RocksDbTable<M, K, V>>,
> OpenTable for T
{
  type Table = <T as TableDesc>::Table;
  fn open() -> Self::Table { unimplemented!() }
}

pub struct TableA;

impl TableDesc for TableA {
    type Table = RocksDbTable<Self, hkt!(Dummy), hkt!((Dummy, Dummy))>;
}

fn issue() {
    let table = <TableA as OpenTable>::open();
    // Works if you change OpenTable to TableDesc on this line:
    struct MyStruct(<TableA as OpenTable>::Table);
    let my_struct = MyStruct(table);
}

I expected to see this happen: Compile successfully, because RocksDbTable has a static size and <TableA as OpenTable>::Table == <TableA as TableDesc>::Table

Instead, this happened: error[E0161]: cannot move a value of type 'MyStruct'

Meta

rustc --version --verbose:

1.94.1 (Rust Playground)

rustc 1.96.0-nightly (20f19f461 2026-03-21) (Locally)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions