Skip to content

Confusing diagnostic for supertrait cycle #80164

Open
@RReverser

Description

@RReverser
pub trait Constant: From<Self::Value> + Into<Self::Value> + Copy + Eq + Ord {
    type Value;
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when computing the supertraits of `Constant`
 --> src/lib.rs:1:1
  |
1 | pub trait Constant: From<Self::Value> + Into<Self::Value> + Copy + Eq + Ord {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: ...which again requires computing the supertraits of `Constant`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> src/lib.rs:1:1
  |
1 | pub trait Constant: From<Self::Value> + Into<Self::Value> + Copy + Eq + Ord {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

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

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

Note: it's possible to reproduce the issue with a lot simpler repro, leaving just the From<Self::Value part, but example with more traits is more problematic, because in that case it's unclear which one of the trait clauses is actually causing the issue.

Note 2: Aside from improving diagnostics, why is this an error at all? There is no trait cycle as far as I can tell, it's just trying to use its own associated type which feels like should be fine...

cc @estebank

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-papercutDiagnostics: An error or lint that needs small tweaks.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