Skip to content

type S = Option<Box<S>>; should compile #63097

Closed
@lihz6

Description

@lihz6

It seems a compiler bug to me. I tried this code:

type S = Option<Box<S>>;

I expected it could compile, but instead:

lihz:linkedlist lihzhang$ cargo build
   Compiling linkedlist v0.1.0 (/Users/lihzhang/Documents/com.github/linkedlist)
error[E0391]: cycle detected when processing `S`
 --> src/lib.rs:1:21
  |
1 | type S = Option<Box<S>>;
  |                     ^
  |
  = note: ...which again requires processing `S`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> src/lib.rs:1:1
  |
1 | type S = Option<Box<S>>;
  | ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0391`.
error: Could not compile `linkedlist`.

To learn more, run the command again with --verbose.

However, the equivalent code as following compiles fine:

enum S {
    T(Option<Box<S>>),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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