-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
use serde::Serialize;
trait Foo {
fn bar(baz: i32, quux: String);
}
impl Foo for () {
fn bar(baz: i32) {
}
}
struct Bar;
impl Serialize for Bar {
fn serialize<S>(&self) {
}
}
fn main() {}Current output
error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 2
--> src/main.rs:8:17
|
4 | fn bar(baz: i32, quux: String);
| ----------------- trait requires 2 parameters
...
8 | fn bar(baz: i32) {
| ^^^ expected 2 parameters, found 1
error[E0050]: method `serialize` has 1 parameter but the declaration in trait `serialize` has 2
--> src/main.rs:16:21
|
16 | fn serialize<S>(&self) {
| ^^^^^ expected 2 parameters, found 1
|
= note: `serialize` from trait: `fn(&Self, S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>`
For more information about this error, try `rustc --explain E0050`.Desired output
error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 2
--> src/main.rs:8:17
|
4 | fn bar(baz: i32, quux: String);
| ----------------- trait requires 2 parameters
...
8 | fn bar(baz: i32) {
| ^^^ expected 2 parameters, found 1
help: modify the signature to match the trait definition
|
8 | fn bar(baz: i32, quux: String) {
| ~~~~~~~~~~~~~~
error[E0050]: method `serialize` has 1 parameter but the declaration in trait `serialize` has 2
--> src/main.rs:16:21
|
16 | fn serialize<S>(&self) {
| ^^^^^ expected 2 parameters, found 1
|
= help: modify the signature to match the trait definition
|
16 | fn serialize(&self, serializer: S) -> Result<S::Ok, S::Error> {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For more information about this error, try `rustc --explain E0050`.Rationale and extra context
The current message is slightly different for local and external traits, but the idea is the same: instead of just writing out the signature, the message could instead suggest adding parameters to exactly match the trait definition.
This is similar to what we already do when a function call expression does not match the function parameters.
Other cases
No response
Anything else?
No response
estebank and reddevilmidzy
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.