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

generic const exprs in diagnostics aren't printed with substs applied #86198

Open
BoxyUwU opened this issue Jun 10, 2021 · 0 comments
Open

generic const exprs in diagnostics aren't printed with substs applied #86198

BoxyUwU opened this issue Jun 10, 2021 · 0 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints 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

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 10, 2021

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

@BoxyUwU BoxyUwU 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 Jun 10, 2021
@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` labels Jun 10, 2021
@BoxyUwU BoxyUwU changed the title confusing diagnostics with const_evaluatable_checked generic const exprs in diagnostics aren't printed with substs applied Jun 24, 2022
@BoxyUwU BoxyUwU removed the F-const_generics `#![feature(const_generics)]` label Jun 24, 2022
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 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.

2 participants