Skip to content

Resolve error in const params doesn't do fuzzy search for consts #149660

@estebank

Description

@estebank

Code

const CONST: usize = 0;

fn foo<const C: usize>() {}

fn main() {
    foo::<CONS>();
}

Current output

error[E0425]: cannot find type `CONS` in this scope
 --> src/main.rs:6:11
  |
6 |     foo::<CONS>();
  |           ^^^^ not found in this scope

error[E0747]: unresolved item provided when a constant was expected
 --> src/main.rs:6:11
  |
6 |     foo::<CONS>();
  |           ^^^^
  |
help: if this generic argument was intended as a const parameter, surround it with braces
  |
6 |     foo::<{ CONS }>();
  |           +      +

Desired output

error[E0425]: cannot find type `CONS` in this scope
 --> src/main.rs:6:11
1 | const CONST: usize = 0;
  |       ----- similarly named `const` `CONST` defined here
  |
6 |     foo::<CONS>();
  |           ^^^^ not found in this scope

Rationale and extra context

We're emitting two errors when one was made, and we already provide fuzzy-search in other resolve errors.

Other cases

Rust Version

Stable to Nightly
1.93.0-nightly
2025-12-03 83e49b75e7daf827e439

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions