suggest adding parameters to exactly match the trait definition#107548
suggest adding parameters to exactly match the trait definition#107548lyming2007 wants to merge 1 commit intorust-lang:masterfrom
Conversation
when the impl of the function doesn't match with the trait declaration
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) soon. Please see the contribution instructions for more information. |
| | | ||
| help: modify the signature to match the trait definition | ||
| | | ||
| LL | (), _: (), _: () {} |
There was a problem hiding this comment.
What happened here?
There was a problem hiding this comment.
oh. That's a bug of my implementation which doesn't consider the impl function being 0 parameters. I'll fix it
| potentially_plural_count(trait_number_args, "parameter") | ||
| ), | ||
| ); | ||
| if let Ok(snip) = tcx.sess.source_map().span_to_snippet(trait_span) { |
There was a problem hiding this comment.
This just copies the contents of the parentheses, right? If so, this doesn't take params into account, I think:
trait Foo {
fn bar<T>(_: T);
}
impl Foo for () {
fn bar<E>(_: E, _: i32) {}
}
which would suggest changing fn bar<E>(_: T) {}
There was a problem hiding this comment.
yes it would suggest:
error[E0050]: method `bar` has 2 parameters but the declaration in trait `Foo::bar` has 1
--> params.rs:6:16
|
2 | fn bar<T>(_: T);
| - trait requires 1 parameter
...
6 | fn bar<E>(_: E, _: i32) {}
| ^^^^^^^^^ expected 1 parameter, found 2
|
help: modify the signature to match the trait definition
|
6 | fn bar<E>(_: T) {}
I think we should suggest it to be fn bar<E>(_: E) {} or fn bar<T>(_: T) {}
There was a problem hiding this comment.
Similarly, we need to consider cases where the arguments reference generics from the trait:
trait Foo<T> {
fn foo(_: T);
}
impl Foo<()> for i32 {
fn foo();
}
Should suggest _: (), not _: T.
|
Gonna mark this as waiting on author. Feel free to ping me for advice, and use r? @compiler-errors |
|
@lyming2007 FYI: when a PR is ready for review, send a message containing |
|
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
when the impl of the function doesn't match with the trait declaration
this will fix #106999