const generics use generic param names in nonsensical ways in error messages, leading to bogus suggestions
Open
@long-long-float is already working on this.
Since Jul 13, 2024.
A-diagnostics
F-generic_const_exprs
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
fn foo<const I: usize, const J: usize>() where [(); I / 4]: {
bar::<J, I>(); // I and J are accidentally swapped
}
fn bar<const I: usize, const J: usize>() where [(); I / 4]: {
[(); I / 4];
}
Current output
error: unconstrained generic constant
--> src/lib.rs:5:11
|
5 | bar::<J, I>(); // I and J are accidentally swapped
| ^
|
note: required by a bound in `bar`
--> src/lib.rs:8:53
|
8 | fn bar<const I: usize, const J: usize>() where [(); I / 4]: {
| ^^^^^ required by this bound in `bar`
help: try adding a `where` bound
|
4 | fn foo<const I: usize, const J: usize>() where [(); I / 4]:, [(); I / 4]: {
| ++++++++++++++
Desired output
the error message should suggest adding [(); J / 4]:, because J in foo corresponds to I in bar. Bonus points if the error message says something like
help: try adding a `where` bound
|
4 | fn foo<const I: usize, const J: usize>() where [(); I / 4]:, [(); J / 4]: {
| ++++++++++++++
note: const param `I` in `bar` corresponds to expression `J` in `foo`
extra bonus points if the error message says something like note: foo and bar both have const generic param named I, but bar::I is not the same as foo::I
Rust Version
nightly on playground as of 2024-7-10
Anything else?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.