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

Suggestion for adding a type parameter happens a little too often. #70365

Closed
ehuss opened this issue Mar 24, 2020 · 0 comments · Fixed by #70912
Closed

Suggestion for adding a type parameter happens a little too often. #70365

ehuss opened this issue Mar 24, 2020 · 0 comments · Fixed by #70912
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Mar 24, 2020

The following code now emits a suggestion to add a type parameter (since #68447 in 1.42):

pub struct S {
    pub f: Option<PathBuf>
}

Emits:

error[E0412]: cannot find type `PathBuf` in this scope
 --> src/lib.rs:2:19
  |
2 |     pub f: Option<PathBuf>
  |                   ^^^^^^^ not found in this scope
  |
help: possible candidate is found in another module, you can import it into scope
  |
1 | use std::path::PathBuf;
  |
help: you might be missing a type parameter
  |
1 | pub struct S<PathBuf> {
  |             ^^^^^^^^^

The suggestion to add <PathBuf> is clearly wrong (in my eyes), and I feel like I am seeing this suggestion a lot.

Perhaps, if there is already a "possible candidate import" suggestion, it could skip the suggestion to add a type parameter? Or maybe some other heuristic to dial back how often it shows up?

(BTW, it is a great suggestion when it applies, but more often than not I'm getting a wrong hint.)

@ehuss ehuss added the C-bug Category: This is a bug. label Mar 24, 2020
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 24, 2020
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Mar 24, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 8, 2020
…bosity, r=davidtwco

Do not suggest adding type param when `use` is already suggested

Fix rust-lang#70365, cc rust-lang#70572.
@bors bors closed this as completed in a3e54b5 Apr 9, 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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. 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.

3 participants