Skip to content

Missing unconstrained generic constant error if adt_const_params feature is included #90531

Closed
@b-naber

Description

@b-naber

Based on the example in #90455, which after the changes in #90529 would output an unconstrained generic constant error. The following code, however, does not output such an error, although I believe it should.

Given the following code:

#![feature(generic_const_exprs, adt_const_params)]

const fn num_limbs(_: &str) -> usize {
    5   
}

fn foo<const N: &'static str>(_arr: [u64; num_limbs(N)]) where [u64; num_limbs(N)]: {}

fn main() {
  let arr = [5; 5];       
  foo(arr);
}

The current output is:

error[E0284]: type annotations needed: cannot satisfy `the constant `foo::<{_: &'static str}>::{constant#0}` can be evaluated`
  --> test2.rs:17:3
   |
17 |   foo(arr);
   |   ^^^ cannot satisfy `the constant `foo::<{_: &'static str}>::{constant#0}` can be evaluated`
   |
note: required by a bound in `foo`
  --> test2.rs:13:70
   |
13 | fn foo<const N: &'static str>(_arr: [u64; num_limbs(N)]) where [u64; num_limbs(N)]: {}
   |                                                                      ^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to previous error; 2 warnings emitted

This only happens if the adt_const_params is included. This also compiles if you don't include the call of foo in main.

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-generic_const_exprs`#![feature(generic_const_exprs)]`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