Skip to content

When suggesting an typo type, do not display whole type body. #70206

Closed
@tesuji

Description

@tesuji

For example, consider this snippet (playground):

pub type Result<T> = std::result::Result<T, Errror>;

/// Error type for Kvs
#[derive(Debug)]
pub enum Error {
    DuplicateKey,
    KeyNotFound,
    UnexpectedCommandType,
}

Currently rustc errors:

error[E0412]: cannot find type `Errror` in this scope
 --> src/lib.rs:1:45
  |
1 |   pub type Result<T> = std::result::Result<T, Errror>;
  |                                               ^^^^^^
...
5 | / pub enum Error {
6 | |     DuplicateKey,
7 | |     KeyNotFound,
8 | |     UnexpectedCommandType,
9 | | }
  | |_- similarly named enum `Error` defined here
  |
help: an enum with a similar name exists
  |
1 | pub type Result<T> = std::result::Result<T, Error>;
  |                                             ^^^^^
help: you might be missing a type parameter
  |
1 | pub type Result<T, Errror> = std::result::Result<T, Errror>;
  |                  ^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

I would like it to highlight only the type name:

error[E0412]: cannot find type `Errror` in this scope
 --> src/lib.rs:1:45
  |
1 |   pub type Result<T> = std::result::Result<T, Errror>;
  |                                               ^^^^^^
...
5 |   pub enum Error {
  |       ^^^^^^^^^^ - similarly named enum `Error` defined here
  |
help: an enum with a similar name exists
  |
1 | pub type Result<T> = std::result::Result<T, Error>;
  |                                             ^^^^^
help: you might be missing a type parameter
  |
1 | pub type Result<T, Errror> = std::result::Result<T, Errror>;
  |                  ^^^^^^^^

Related issue on clippy: rust-lang/rust-clippy#5284

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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