Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum variant with GAT field fails to derive Sized #80626

Closed
zygi opened this issue Jan 2, 2021 · 5 comments
Closed

Enum variant with GAT field fails to derive Sized #80626

zygi opened this issue Jan 2, 2021 · 5 comments
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs GATs-triaged Issues using the `generic_associated_types` feature that have been triaged S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test.

Comments

@zygi
Copy link

zygi commented Jan 2, 2021

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
@zygi zygi added the C-bug Category: This is a bug. label Jan 2, 2021
@zygi zygi changed the title Enum with GAT member fails to derive Sized Enum variant with GAT field fails to derive Sized Jan 2, 2021
@jonas-schievink jonas-schievink added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Jan 2, 2021
@jedel1043
Copy link
Contributor

Surprisingly, this also doesn't compile:

#![feature(generic_associated_types)]
#![allow(incomplete_features)]

trait Allocator {
    type Allocated<T>;
}

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

fn main() {}

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

@4lDO2
Copy link

4lDO2 commented Jun 20, 2021

I have checked that changing type Allocated<T>; to type Allocated<T>; Sized has no effect at all, as to be expected. But when opting out of Sized using type Allocated<T>: ?Sized; seems to prevent it from overflowing, though still obviously not compiling.

@aleksmelnikov
Copy link

aleksmelnikov commented Jun 21, 2021

Examples that compile:

#![feature(generic_associated_types)]
#![allow(incomplete_features)]

trait Allocator {
    type Allocated<T>;
}

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

fn main() {}
#![feature(generic_associated_types)]
#![allow(incomplete_features)]

trait Allocator {
    type Allocated<T>;
}

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

fn main() {}
#![feature(generic_associated_types)]
#![allow(incomplete_features)]

trait Allocator {
    type Allocated<T>;
}

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

fn main() {}

@jackh726
Copy link
Member

GATs issue triage: not blocking. While this bug is unfortunate, this isn't really a GATs problem, per se. Proper fix is probably a coinductive Sized. Workaround is a ?Sized bound.

@jackh726 jackh726 added the GATs-triaged Issues using the `generic_associated_types` feature that have been triaged label Oct 16, 2021
@jackh726 jackh726 added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Mar 12, 2022
@Dylan-DPC
Copy link
Member

This code now compiles fine without the above error

@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs GATs-triaged Issues using the `generic_associated_types` feature that have been triaged S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test.
Projects
None yet
8 participants