Skip to content

Suggest annotating traits rather than methods when appropriate #89064

Closed

Description

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d2a32fe1f3460b6583534eb53d045165

fn foo() {
    let _ = "foo".into::<Option<_>>();
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied
   --> src/lib.rs:2:19
    |
2   |     let _ = "foo".into::<Option<_>>();
    |                   ^^^^------------- help: remove these generics
    |                   |
    |                   expected 0 generic arguments
    |
note: associated function defined here, with 0 generic parameters

For more information about this error, try `rustc --explain E0107`.
error: could not compile `playground` due to previous error

Ideally the output should look like:

error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied
   --> src/lib.rs:2:19
    |
2   |     let _ = "foo".into::<Option<_>>();
    |                   ^^^^------------- help: remove these generics
    |                   |
    |                   expected 0 generic arguments
    |
note: associated function defined here, with 0 generic parameters
help: `Into` trait takes 1 generic argument, try annotating that instead: `Into::<Option<_>>::into("foo")

When a user called into() with an annotation, it's helpful to suggest T::from(_) too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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