-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsF-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code: link
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
trait Trait {}
struct HasCastInTraitImpl<const N: usize, const M: usize>;
impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
pub struct HasTrait<T: Trait>(T);
fn foo<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1 }, { N + 1}>> { loop {} }
fn main() {}
The current output is:
error: unconstrained generic constant
--> src/main.rs:8:29
|
7 | pub struct HasTrait<T: Trait>(T);
| ----- required by this bound in `HasTrait`
8 | fn foo<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1 }, { N + 1}>> { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1 }, { N + 1}>`
--> src/main.rs:6:22
|
6 | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> src/main.rs:8:29
|
8 | fn foo<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1 }, { N + 1}>> { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N + 1}`, found `{ M + 1 }`
|
= note: expected type `{ N + 1}`
found type `{ M + 1 }`
error: aborting due to 2 previous errors
Ideally the output should look like:
error[E0308]: mismatched types
--> src/main.rs:8:29
|
8 | fn foo<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1 }, { N + 1}>> { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N + 1}`, found `{ (N + 1) + 1 }`
|
= note: expected type `{ N + 1}`
found type `{ (N + 1) + 1 }`
@rustbot label: +A-const-generics +F-const_generics +F-const_evaluatable_checked
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsF-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.