Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tesuji opened this issue Mar 21, 2020 · 1 comment · Fixed by #70227
Closed

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

tesuji opened this issue Mar 21, 2020 · 1 comment · Fixed by #70227
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Mar 21, 2020

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

@Centril
Copy link
Contributor

Centril commented Mar 21, 2020

Sounds like a good improvement. This should be as easy as replacing the relevant span with sm.def_span(span).

@Centril Centril added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Mar 21, 2020
Centril added a commit to Centril/rust that referenced this issue Mar 22, 2020
Only display definition when suggesting a typo

Closes rust-lang#70206
r? @Centril
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 22, 2020
Only display definition when suggesting a typo

Closes rust-lang#70206
r? @Centril
Centril added a commit to Centril/rust that referenced this issue Mar 23, 2020
Only display definition when suggesting a typo

Closes rust-lang#70206
r? @Centril
@bors bors closed this as completed in 11f5309 Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants