Skip to content

cycle errors for unevaluated constants in the param env #79356

Open
@lcnr

Description

@lcnr
// check-pass
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

struct Foo<T>(T);

fn test() where [u8; {
    let _: Foo<[u8; 3 + 4]>;
    3
}]: Sized {}

ends up failing with

error[E0391]: cycle detected when simplifying constant for the type system `test::{constant#0}`
  --> src/lib.rs:7:22
   |
7  |   fn test() where [u8; {
   |  ______________________^
8  | |     let _: Foo<[u8; 3 + 4]>;
9  | |     3
10 | | }]: Sized {
   | |_^
   |
note: ...which requires const-evaluating + checking `test::{constant#0}`...
  --> src/lib.rs:7:22
   |
7  |   fn test() where [u8; {
   |  ______________________^
8  | |     let _: Foo<[u8; 3 + 4]>;
9  | |     3
10 | | }]: Sized {
   | |_^
note: ...which requires type-checking `test::{constant#0}`...
  --> src/lib.rs:7:22
   |
7  |   fn test() where [u8; {
   |  ______________________^
8  | |     let _: Foo<[u8; 3 + 4]>;
9  | |     3
10 | | }]: Sized {
   | |_^
   = note: ...which requires evaluating trait selection obligation `[u8; _]: std::marker::Sized`...
   = note: ...which again requires simplifying constant for the type system `test::{constant#0}`, completing the cycle
note: cycle used when checking that `test` is well-formed
  --> src/lib.rs:10:5
   |
10 | }]: Sized {
   |     ^^^^^

The cycle happens while typechecking the outer array length. This happens because Foo<[u8; 3 + 4]> requires [u8; 3 + 4] to be sized. While trying to fulfill this we see the [u8; ...]: Sized bound in the param_env and try to unify these two. This causes us to evaluate both constants which once again relies on typechecking them.

*This test succeeds with min_const_generics and currently fails with const_generics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`I-cycleIssue: A query cycle occurred while none was expectedP-lowLow priorityT-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