Skip to content

unhelpful drop check cycle encountered errors on infinite-sized recursive enum with a boxed variant #99061

Open
@pro465

Description

@pro465

I tried this code:

enum List<S> {
    Cons(S, Box<List<S>>),
    One(List<S>),
    None,
}

fn main() {
    let c: List<i32>;
}

I expected to see this happen: just error messages about infinite sized List

Instead, this happened: errored out as

error[E0072]: recursive type `List` has infinite size
 --> /data/data/com.termux/files/home/test.rs:1:1
  |
1 | enum List<S> {
  | ^^^^^^^^^^^^ recursive type has infinite size
2 |     Cons(S, Box<List<S>>),
3 |     One(List<S>),
  |         ------- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable
  |
3 |     One(Box<List<S>>),
  |         ++++       +

error[E0391]: cycle detected when computing drop-check constraints for `List`
 --> /data/data/com.termux/files/home/test.rs:1:1
  |
1 | enum List<S> {
  | ^^^^^^^^^^^^
  |
  = note: ...which immediately requires computing drop-check constraints for `List` again
  = note: cycle used when computing dropck types for `Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing, constness: NotConst }, value: List<i32> } }`                                       
error: aborting due to 2 previous errors

Meta

rustc --version --verbose:

rustc 1.61.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: armv7-linux-androideabi
release: 1.61.0
LLVM version: 14.0.3
Backtrace

<no backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions