-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Diagnostics hint for const generics #80506
Copy link
Copy link
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 lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-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
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 lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-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.
Current Behavior
Given the following code:
where
Iterator::combinationsis defined as:The following diagnostic is provided:
error[E0282]: type annotations needed --> src\lib.rs:144:32 | 144 | let mut combinations = (1..2).combinations(); | ^^^^^^^^^^^^^^^^^^^^^ | = note: unable to infer the value of a const parameterAttempting a fix, and failing:
Naively I thought I could fix this by adding a turbofish, but that doesn't seem to help:
error[E0107]: wrong number of const arguments: expected 1, found 0 --> src\lib.rs:144:39 | 144 | let mut combinations = (1..2).combinations::<[usize; 2]>(); | ^^^^^^^^^^^^ expected 1 const argument error[E0107]: wrong number of type arguments: expected 0, found 1 --> src\lib.rs:144:54 | 144 | let mut combinations = (1..2).combinations::<[usize; 2]>(); | ^^^^^^^^^^ unexpected type argumentExpected behavior
Providing a hint on how to correctly define const generics would be immensely helpful. I'm sure I'll be able to figure out the syntax for this eventually (currently going through #78460 among others), but given we're set for a 1.51 stabilization of
min_const_genericsI suspect more people will be running into this soon.Further Considerations
I was looking at how hints work for e.g. missing type params in
collect, and noticed no hints are provided there either. It only explains what to do, not showing how to do it. For something that's notoriously tricky to learn that seems like it could benefit from hints as well.