Skip to content

Fn traits with array args no longer work with const_generics enabled #67753

Closed
@Manishearth

Description

@Manishearth
#![feature(const_generics)]

fn main() {
    takes_closure_of_array_3(|[x, y, z]| {
        println!("args: x={}, y={}, z={}", x, y, z);
    });
}

fn takes_closure_of_array_3<F>(f: F)
where
    F: Fn([i32; 3]),
{
    f([1, 2, 3]);
}

(playpen)

Gives the error:

   Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error[E0391]: cycle detected when const-evaluating + checking `takes_closure_of_array_3::{{constant}}#0`
  --> src/main.rs:11:17
   |
11 |     F: Fn([i32; 3]),
   |                 ^
   |
note: ...which requires const-evaluating + checking `takes_closure_of_array_3::{{constant}}#0`...
  --> src/main.rs:11:17
   |
11 |     F: Fn([i32; 3]),
   |                 ^
......................
9  | / fn takes_closure_of_array_3<F>(f: F)
10 | | where
11 | |     F: Fn([i32; 3]),
12 | | {
13 | |     f([1, 2, 3]);
14 | | }
   | |_^

This compiles fine with const_generics not enabled, and is a regression

cc @Centril @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]`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