Skip to content

Enum variant with GAT field fails to derive Sized #80626

Closed
@zygi

Description

@zygi

I tried this code:

#![feature(generic_associated_types)]

trait Allocator {
    type Allocated<T>;
}

enum LinkedList<A: Allocator> {
    Head,
    Next(A::Allocated<Self>)
}

fn main() {}

I expected to see this happen: Enum successfully compiles and can be constructed.

Instead, this happened:

error[E0275]: overflow evaluating the requirement '<A as Allocator>::Allocated<CLinkedList<A>>: Sized'

Interestingly, this compiles:

#![feature(generic_associated_types)]

trait Allocator {
    type Allocated<T>;
}

enum CLinkedList<A: Allocator> {
    Head,
    Next(A::Allocated<Self>, i64)
}

fn main() {}

As does this:

#![feature(generic_associated_types)]

trait Allocator {
    type Allocated<T>;
}

struct LinkedListStruct<A: Allocator> {
    value: i64,
    next: Option<A::Allocated<Self>>
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (17eec1433 2021-01-01)
binary: rustc
commit-hash: 17eec1433c69972844dd228b5fe801f218e118c3
commit-date: 2021-01-01
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)C-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsGATs-triagedIssues using the `generic_associated_types` feature that have been triagedS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions