Skip to content

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

@Manishearth

Description

@Manishearth
Member
#![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

Activity

Manishearth

Manishearth commented on Dec 31, 2019

@Manishearth
MemberAuthor

(discovered by @jcoglan)

added
A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)
requires-nightlyThis issue requires a nightly compiler in some way.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Dec 31, 2019
Centril

Centril commented on Dec 31, 2019

@Centril
Contributor

cc @nikomatsakis @eddyb @varkor

Simplified:

#![feature(const_generics)]

fn main() {
    takes_closure_of_array(|_| {});
}

fn takes_closure_of_array<F>(f: F)
where
    F: FnOnce([i32; 0]),
{
    f([]);
}
jonas-schievink

jonas-schievink commented on Dec 31, 2019

@jonas-schievink
Contributor

Isn't this expected fallout?

varkor

varkor commented on Dec 31, 2019

@varkor
Contributor

This is an expected consequence of #66883.

1 remaining item

pnkfelix

pnkfelix commented on Jan 2, 2020

@pnkfelix
Contributor

triage: P-medium (nightly-only regression on feature that is known to have bugs)

eddyb

eddyb commented on Jan 16, 2020

@eddyb
Member

@varkor @oli-obk I think we've discussed this before, but what do you think of special-casing literals, to unblock at least some common usecases like this?

oli-obk

oli-obk commented on Jan 17, 2020

@oli-obk
Contributor

I can't reproduce on master, this may have gotten fixed? (Note that the playground is severely outdated, a fix is underway for that though)

added
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
on Jan 17, 2020
varkor

varkor commented on Jan 17, 2020

@varkor
Contributor

@eddyb pointed out that #68118 most likely fixed this.

removed
requires-nightlyThis issue requires a nightly compiler in some way.
on Jan 17, 2020
added 3 commits that reference this issue on Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @eddyb@pnkfelix@oli-obk@Centril@Manishearth

      Issue actions

        Fn traits with array args no longer work with const_generics enabled · Issue #67753 · rust-lang/rust