Skip to content

diagnostics for E404 suggests use which already exists #120559

Closed
@jendrikw

Description

@jendrikw

(A better title would be appreciated)

Code

use std::io::Read;

fn f<T: Read, U, Read>() {}

Current output

Compiling playground v0.0.1 (/playground)
error[E0404]: expected trait, found type parameter `Read`
 --> src/lib.rs:3:9
  |
1 | use std::io::Read;
  |              ---- you might have meant to refer to this trait
2 |
3 | fn f<T: Read, U, Read>() {}
  |         ^^^^     ---- found this type parameter
  |         |
  |         not a trait
  |
help: consider importing one of these items instead
  |
1 + use exr::io::Read;
  |
1 + use hyper::rt::Read;
  |
1 + use serde_json::de::Read;
  |
1 + use std::io::Read;
  |

Desired output

I like this part:

 --> src/lib.rs:3:9
  |
1 | use std::io::Read;
  |              ---- you might have meant to refer to this trait
2 |
3 | fn f<T: Read, U, Read>() {}
  |         ^^^^     ---- found this type parameter
  |         |
  |         not a trait

It could have a suggestion like did you mean : instead of ,, especially because ,<.>;: are very close to each other on a US keyboard and could very well be a typo.

Rationale and extra context

Applying the suggestion use std::io::Read will result in a compile error.

Other cases

No response

Rust Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6

Also reproducable with current playground nightly (1.77.0)

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.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