Skip to content

Tweak output on misused const parameter to provide more context and more accurate suggestion - #164775

Open
estebank wants to merge 4 commits into
rust-lang:mainfrom
estebank:missing-const-param
Open

estebank wants to merge 4 commits into
rust-lang:mainfrom
estebank:missing-const-param

Conversation

@estebank

@estebank estebank commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

When missing const param in impl, provide complete suggestion:

error[E0107]: missing generics for struct `a::Foo`
  --> $DIR/impl-block-missing-const-generics.rs:6:10
   |
LL |     impl Foo {}
   |          ^^^ expected 1 generic argument
   |
note: struct defined here, with 1 generic parameter: `AHA`
  --> $DIR/impl-block-missing-const-generics.rs:4:12
   |
LL |     struct Foo<const AHA: usize>{}
   |            ^^^ ----------------
help: add missing generic argument
   |
LL |     impl<const AHA: usize> Foo<AHA> {}
   |         ++++++++++++++++++    +++++

Previously we only suggested Foo<AHA> without the impl<const AHA: usize>.

Fix #91119.

Point at const param declaration when constant is not expected type:

error: the constant `N` is not of type `usize`
  --> $DIR/const-in-impl-fn-return-type.rs:12:32
   |
LL |     fn func<const N: u32>() -> [(); N];
   |             ------------       ^^^^^^^ expected `usize`, found `u32`
   |             |
   |             found this const parameter
   |
   = note: the length of array `[(); N]` must be type `usize`

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 23, 2026
@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@estebank
estebank force-pushed the missing-const-param branch from ddff73d to aa81524 Compare October 23, 2026 02:52
```
error[E0107]: missing generics for struct `a::Foo`
  --> $DIR/impl-block-missing-const-generics.rs:6:10
   |
LL |     impl Foo {}
   |          ^^^ expected 1 generic argument
   |
note: struct defined here, with 1 generic parameter: `AHA`
  --> $DIR/impl-block-missing-const-generics.rs:4:12
   |
LL |     struct Foo<const AHA: usize>{}
   |            ^^^ ----------------
help: add missing generic argument
   |
LL |     impl<const AHA: usize> Foo<AHA> {}
   |         ++++++++++++++++++    +++++
```

Previously we only suggested `Foo<AHA>` without the `impl<const AHA: usize>`.
```
error: the constant `N` is not of type `usize`
  --> $DIR/const-in-impl-fn-return-type.rs:12:32
   |
LL |     fn func<const N: u32>() -> [(); N];
   |             ------------       ^^^^^^^ expected `usize`, found `u32`
   |             |
   |             found this const parameter
   |
   = note: the length of array `[(); N]` must be type `usize`
```
```
error: the constant `B` is not of type `usize`
  --> $DIR/check_const_arg_type_in_free_alias.rs:15:30
   |
LL | type ArrLen<const B: bool> = [(); B];
   |             -------------    ^^^^^^^ expected `usize`, found `bool`
   |             |
   |             found this const parameter
   |
   = note: the length of array `[(); B]` must be type `usize`
```
@estebank
estebank force-pushed the missing-const-param branch from aa81524 to d5fa09c Compare October 23, 2026 17:40
@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Oct 23, 2026
@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@estebank
estebank force-pushed the missing-const-param branch from d5fa09c to 69d8e14 Compare October 23, 2026 19:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler error messages leads to wrong usage of const generics

4 participants