Skip to content

Invalid "a constant with a similar name exists: _" suggestion when a const _ is in scope #68719

Closed
@ollie27

Description

@ollie27

For example (playground):

const _: () = ();

fn main() {
    a
}

Errors with:

error[E0425]: cannot find value `a` in this scope
 --> src/main.rs:4:5
  |
1 | const _: () = ();
  | ----------------- similarly named constant `_` defined here
...
4 |     a
  |     ^ help: a constant with a similar name exists: `_`

The same also happens with use Trait as _ (playground):

pub use Iterator as _;

fn foo<T: A>(x: T) {}
error[E0405]: cannot find trait `A` in this scope
    --> src/lib.rs:3:11
     |
3    |   fn foo<T: A>(x: T) {}
     |             ^ help: a trait with a similar name exists: `_`

The diagnostics shouldn't suggest things named underscore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in 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