Skip to content

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

Closed
@ehuss

Description

@ehuss

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of 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