Skip to content

False-positive "cycle detected" in const fn with RPIT #99793

Closed
@yvt

Description

@yvt

I tried this code:

const fn f() -> impl Eq { g() }
const fn g() {}
// OK: const fn f() -> impl Eq { g(); }
// OK: const fn f() -> impl Eq {}
// OK: const fn f() -> impl Eq { (g(),).0 }

(Playground)

I expected to see this happen: Successful compilation

Instead, this happened:

error[E0391]: cycle detected when computing type of `f::{opaque#0}`
 --> src/lib.rs:1:17
  |
1 | const fn f() -> impl Eq { g() }
  |                 ^^^^^^^
  |
note: ...which requires borrow-checking `f`...
 --> src/lib.rs:1:1
  |
1 | const fn f() -> impl Eq { g() }
  | ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires processing `f`...
 --> src/lib.rs:1:1
  |
1 | const fn f() -> impl Eq { g() }
  | ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const checking `f`...
 --> src/lib.rs:1:1
  |
1 | const fn f() -> impl Eq { g() }
  | ^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which requires computing whether `impl core::cmp::Eq` is freeze...
  = note: ...which requires evaluating trait selection obligation `impl core::cmp::Eq: core::marker::Freeze`...
  = note: ...which again requires computing type of `f::{opaque#0}`, completing the cycle
note: cycle used when checking item types in top-level module
 --> src/lib.rs:1:1
  |
1 | const fn f() -> impl Eq { g() }
  | ^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0391`.

Meta

rustc --version --verbose:

rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-unknown-linux-gnu
release: 1.62.1
LLVM version: 14.0.5
rustc 1.64.0-nightly (6dbae3ad1 2022-07-25)
binary: rustc
commit-hash: 6dbae3ad19309bb541d9e76638e6aa4b5449f29a
commit-date: 2022-07-25
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-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