Skip to content

Bogus error in beta and nightly: recursive type has infinite size #31299

Closed
@jorendorff

Description

@jorendorff
trait Front {
    type Back;
}

impl<T> Front for Vec<T> {
    type Back = Vec<T>;
}

struct PtrBack<T: Front>(*mut T::Back);

struct M(PtrBack<Vec<M>>);

fn main() {
    println!("{}", std::mem::size_of::<M>());
}

This program prints 8 in Stable (1.5.0), but in Beta and Nightly compilation fails with:

<anon>:11:1: 11:27 error: recursive type `M` has infinite size [E0072]
<anon>:11 struct M(PtrBack<Vec<M>>);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:11:1: 11:27 help: see the detailed explanation for E0072
<anon>:11:1: 11:27 help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `M` representable
<anon>:11:1: 11:27 note: type `M` is embedded within `PtrBack<collections::vec::Vec<M>>`...
<anon>:11:1: 11:27 note: ...which in turn is embedded within `PtrBack<collections::vec::Vec<M>>`...
<anon>:11:1: 11:27 note: ...which in turn is embedded within `M`, completing the cycle.

From 8 bytes to infinity would seem to be a serious memory usage regression.

Metadata

Metadata

Assignees

Labels

P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions