Skip to content

Conversation

@estebank
Copy link
Contributor

@estebank estebank commented Jan 13, 2026

When encountering code like impl<N> Bar<N> for [u8; N], suggest impl<const N: Type> Bar<N> for [u8; N] as a possibility.

error[E0423]: expected value, found type parameter `T`
  --> $DIR/issue-69654.rs:5:25
   |
LL | impl<T> Bar<T> for [u8; T] {}
   |      -                  ^ not a value
   |      |
   |      found this type parameter
   |
help: you might have meant to write a const parameter here
   |
LL | impl<const T: Type> Bar<T> for [u8; T] {}
   |      +++++  ++++++

Addresses "case 3" from #84327.

@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 Jan 13, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

r? @petrochenkov

rustbot has assigned @petrochenkov.
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

@estebank
Copy link
Contributor Author

The logic could be made more complex to ensure that the type param isn't being used anywhere in the TypeNS, which would tell us that the suggestion would be less likely to be correct.

}) else {
return;
};
err.subdiagnostic(errors::UnexpectedResChangeImplTyParamToConstParamSugg {
Copy link
Member

@fmease fmease Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…Impl…

Doesn't this also trigger outside of impls? E.g., on fn f<N>(_: [(); N]) {}?

Maybe rename the preexisting diag struct (the one for N: Typeconst N: Type) to …BoundedTyParam… & remove Impl from this one? Idk, sth. like that

@fmease
Copy link
Member

fmease commented Jan 13, 2026

@bors rollup

Thanks! r=me with nit addressed in one way or another

@fmease fmease assigned fmease and unassigned petrochenkov Jan 13, 2026
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 13, 2026
When encountering code like `impl<N> Bar<N> for [u8; N]`, suggest `impl<const N: Type> Bar<N> for [u8; N]` as a possibility.

```
error[E0423]: expected value, found type parameter `T`
  --> $DIR/issue-69654.rs:5:25
   |
LL | impl<T> Bar<T> for [u8; T] {}
   |      -                  ^ not a value
   |      |
   |      found this type parameter
   |
help: you might have meant to write a const parameter here
   |
LL | impl<const T: /* Type */> Bar<T> for [u8; T] {}
   |      +++++  ++++++++++++
```
@estebank
Copy link
Contributor Author

@bors r=fmease

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 14, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 14, 2026

📌 Commit 15d8e9e has been approved by fmease

It is now in the queue for this repository.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 14, 2026
Recognize potential `impl<const N: usize>` to `impl<N>` mistake

When encountering code like `impl<N> Bar<N> for [u8; N]`, suggest `impl<const N: Type> Bar<N> for [u8; N]` as a possibility.

```
error[E0423]: expected value, found type parameter `T`
  --> $DIR/issue-69654.rs:5:25
   |
LL | impl<T> Bar<T> for [u8; T] {}
   |      -                  ^ not a value
   |      |
   |      found this type parameter
   |
help: you might have meant to write a const parameter here
   |
LL | impl<const T: Type> Bar<T> for [u8; T] {}
   |      +++++  ++++++
```

Addresses "case 3" from rust-lang#84327.
rust-bors bot pushed a commit that referenced this pull request Jan 14, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #149408 (refactor: remove Ord bound from BinaryHeap::new etc)
 - #150406 (Change some `matches!(.., .. if ..)` with let-chains)
 - #150723 (std: move `errno` and related functions into `sys::io`)
 - #150877 (resolve: Refactor away the side table `decl_parent_modules`)
 - #150902 (Update to_uppercase docs to avoid ß->SS example)
 - #150962 (Remove `FeedConstTy` and provide ty when lowering const arg)
 - #151034 (std: Change UEFI env vars to volatile storage)
 - #151036 (Better handle when trying to iterate on a `Range` of a type that isn't `Step`)
 - #151067 (Avoid should-fail in two ui tests and a codegen-llvm test)
 - #151072 (also handle ENOTTY ioctl errors when checking pidfd -> pid support)
 - #151077 (Recognize potential `impl<const N: usize>` to `impl<N>` mistake)
 - #151096 (Remove `Deref`/`DerefMut` impl for `Providers`.)

Failed merges:

 - #150939 (resolve: Relax some asserts in glob overwriting and add tests)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 14, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #149408 (refactor: remove Ord bound from BinaryHeap::new etc)
 - #150406 (Change some `matches!(.., .. if ..)` with let-chains)
 - #150723 (std: move `errno` and related functions into `sys::io`)
 - #150877 (resolve: Refactor away the side table `decl_parent_modules`)
 - #150902 (Update to_uppercase docs to avoid ß->SS example)
 - #151034 (std: Change UEFI env vars to volatile storage)
 - #151036 (Better handle when trying to iterate on a `Range` of a type that isn't `Step`)
 - #151067 (Avoid should-fail in two ui tests and a codegen-llvm test)
 - #151072 (also handle ENOTTY ioctl errors when checking pidfd -> pid support)
 - #151077 (Recognize potential `impl<const N: usize>` to `impl<N>` mistake)
 - #151096 (Remove `Deref`/`DerefMut` impl for `Providers`.)

Failed merges:

 - #150939 (resolve: Relax some asserts in glob overwriting and add tests)

r? @ghost
@rust-bors rust-bors bot merged commit 18c62b5 into rust-lang:main Jan 14, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 14, 2026
rust-timer added a commit that referenced this pull request Jan 14, 2026
Rollup merge of #151077 - issue-84327, r=fmease

Recognize potential `impl<const N: usize>` to `impl<N>` mistake

When encountering code like `impl<N> Bar<N> for [u8; N]`, suggest `impl<const N: Type> Bar<N> for [u8; N]` as a possibility.

```
error[E0423]: expected value, found type parameter `T`
  --> $DIR/issue-69654.rs:5:25
   |
LL | impl<T> Bar<T> for [u8; T] {}
   |      -                  ^ not a value
   |      |
   |      found this type parameter
   |
help: you might have meant to write a const parameter here
   |
LL | impl<const T: Type> Bar<T> for [u8; T] {}
   |      +++++  ++++++
```

Addresses "case 3" from #84327.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 14, 2026
Recover parse gracefully from `<const N>`

When a const param doesn't have a `: Type`, recover the parser state and provide a structured suggestion. This not only provides guidance on what was missing, but it also makes subsuequent errors to be emitted that would otherwise be silenced.

```
error: expected `:`, found `>`
  --> $DIR/incorrect-const-param.rs:26:16
   |
LL | impl<T, const N> From<[T; N]> for VecWrapper<T>
   |                ^ expected `:`
   |
help: you might have meant to write the type of the const parameter here
   |
LL | impl<T, const N: /* Type */> From<[T; N]> for VecWrapper<T>
   |                ++++++++++++
```

r? @fmease

Follow up to rust-lang#151077. Fix rust-lang#84327.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 14, 2026
Recover parse gracefully from `<const N>`

When a const param doesn't have a `: Type`, recover the parser state and provide a structured suggestion. This not only provides guidance on what was missing, but it also makes subsuequent errors to be emitted that would otherwise be silenced.

```
error: expected `:`, found `>`
  --> $DIR/incorrect-const-param.rs:26:16
   |
LL | impl<T, const N> From<[T; N]> for VecWrapper<T>
   |                ^ expected `:`
   |
help: you might have meant to write the type of the const parameter here
   |
LL | impl<T, const N: /* Type */> From<[T; N]> for VecWrapper<T>
   |                ++++++++++++
```

r? @fmease

Follow up to rust-lang#151077. Fix rust-lang#84327.
rust-timer added a commit that referenced this pull request Jan 15, 2026
Rollup merge of #151099 - issue-84327-2, r=fmease

Recover parse gracefully from `<const N>`

When a const param doesn't have a `: Type`, recover the parser state and provide a structured suggestion. This not only provides guidance on what was missing, but it also makes subsuequent errors to be emitted that would otherwise be silenced.

```
error: expected `:`, found `>`
  --> $DIR/incorrect-const-param.rs:26:16
   |
LL | impl<T, const N> From<[T; N]> for VecWrapper<T>
   |                ^ expected `:`
   |
help: you might have meant to write the type of the const parameter here
   |
LL | impl<T, const N: /* Type */> From<[T; N]> for VecWrapper<T>
   |                ++++++++++++
```

r? @fmease

Follow up to #151077. Fix #84327.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 15, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#149408 (refactor: remove Ord bound from BinaryHeap::new etc)
 - rust-lang/rust#150406 (Change some `matches!(.., .. if ..)` with let-chains)
 - rust-lang/rust#150723 (std: move `errno` and related functions into `sys::io`)
 - rust-lang/rust#150877 (resolve: Refactor away the side table `decl_parent_modules`)
 - rust-lang/rust#150902 (Update to_uppercase docs to avoid ß->SS example)
 - rust-lang/rust#151034 (std: Change UEFI env vars to volatile storage)
 - rust-lang/rust#151036 (Better handle when trying to iterate on a `Range` of a type that isn't `Step`)
 - rust-lang/rust#151067 (Avoid should-fail in two ui tests and a codegen-llvm test)
 - rust-lang/rust#151072 (also handle ENOTTY ioctl errors when checking pidfd -> pid support)
 - rust-lang/rust#151077 (Recognize potential `impl<const N: usize>` to `impl<N>` mistake)
 - rust-lang/rust#151096 (Remove `Deref`/`DerefMut` impl for `Providers`.)

Failed merges:

 - rust-lang/rust#150939 (resolve: Relax some asserts in glob overwriting and add tests)

r? @ghost
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 15, 2026
Recover parse gracefully from `<const N>`

When a const param doesn't have a `: Type`, recover the parser state and provide a structured suggestion. This not only provides guidance on what was missing, but it also makes subsuequent errors to be emitted that would otherwise be silenced.

```
error: expected `:`, found `>`
  --> $DIR/incorrect-const-param.rs:26:16
   |
LL | impl<T, const N> From<[T; N]> for VecWrapper<T>
   |                ^ expected `:`
   |
help: you might have meant to write the type of the const parameter here
   |
LL | impl<T, const N: /* Type */> From<[T; N]> for VecWrapper<T>
   |                ++++++++++++
```

r? @fmease

Follow up to rust-lang/rust#151077. Fix rust-lang/rust#84327.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants