Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
b-naber opened this issue Nov 3, 2021 · 4 comments · Fixed by #99222
Closed
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@b-naber
Copy link
Contributor

b-naber commented Nov 3, 2021

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.

@b-naber b-naber added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 3, 2021
@b-naber b-naber changed the title Missing unconstrained generic constant if adt_const_params feature is included Missing unconstrained generic constant error if adt_const_params feature is included Nov 3, 2021
@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-adt_const_params `#![feature(adt_const_params)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Nov 3, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 24, 2022

dont think this is related to adt_const_params as this has the same error:

#![feature(generic_const_exprs)]

fn foo<const N: usize>(_arr: [u64; N + 1]) where [u64; N + 1]: {}

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

@BoxyUwU BoxyUwU removed the F-adt_const_params `#![feature(adt_const_params)]` label Jun 24, 2022
@lcnr
Copy link
Contributor

lcnr commented Jun 24, 2022

the reason this happens is because from some_expr(N) == 5 we don't infer the value for N.

The error message should be improved by using emit_inference_failure_err in this branch

_ => {
if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors() {
return;
}
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0284,
"type annotations needed: cannot satisfy `{}`",
predicate,
);
err.span_label(span, &format!("cannot satisfy `{}`", predicate));
err
}

for that the predicates should be searched for a relevant inference variable.

@lcnr lcnr added E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Jun 24, 2022
@lcnr
Copy link
Contributor

lcnr commented Jun 24, 2022

going to mentor this issue in case someone wants to fix this

@atsuzaki
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants