Suggest changing impl parameter types to match trait

This is particularly useful for cases where arbitrary self types are
used, like in custom `Future`s.
This commit is contained in:
Esteban Küber 2021-04-08 13:50:47 -07:00
parent d43ede10e4
commit 147649d4b9
12 changed files with 151 additions and 25 deletions

View file

@ -8,7 +8,7 @@ LL | fn bar(&mut self, other: &dyn Foo) {}
| ^^^^^^^^
| |
| types differ in mutability
| help: consider changing the mutability to match the trait: `&mut dyn Foo`
| help: change the parameter type to match the trait: `&mut dyn Foo`
|
= note: expected fn pointer `fn(&mut Baz, &mut dyn Foo)`
found fn pointer `fn(&mut Baz, &dyn Foo)`

View file

@ -4,7 +4,10 @@ error[E0053]: method `call` has an incompatible type for trait
LL | impl<'a, T> Fn<(&'a T,)> for Foo {
| - this type parameter
LL | extern "rust-call" fn call(&self, (_,): (T,)) {}
| ^^^^ expected `&T`, found type parameter `T`
| ^^^^
| |
| expected `&T`, found type parameter `T`
| help: change the parameter type to match the trait: `(&'a T,)`
|
= note: expected fn pointer `extern "rust-call" fn(&Foo, (&'a T,))`
found fn pointer `extern "rust-call" fn(&Foo, (T,))`
@ -15,7 +18,10 @@ error[E0053]: method `call_mut` has an incompatible type for trait
LL | impl<'a, T> FnMut<(&'a T,)> for Foo {
| - this type parameter
LL | extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {}
| ^^^^ expected `&T`, found type parameter `T`
| ^^^^
| |
| expected `&T`, found type parameter `T`
| help: change the parameter type to match the trait: `(&'a T,)`
|
= note: expected fn pointer `extern "rust-call" fn(&mut Foo, (&'a T,))`
found fn pointer `extern "rust-call" fn(&mut Foo, (T,))`
@ -27,7 +33,10 @@ LL | impl<'a, T> FnOnce<(&'a T,)> for Foo {
| - this type parameter
...
LL | extern "rust-call" fn call_once(self, (_,): (T,)) {}
| ^^^^ expected `&T`, found type parameter `T`
| ^^^^
| |
| expected `&T`, found type parameter `T`
| help: change the parameter type to match the trait: `(&'a T,)`
|
= note: expected fn pointer `extern "rust-call" fn(Foo, (&'a T,))`
found fn pointer `extern "rust-call" fn(Foo, (T,))`

View file

@ -5,7 +5,10 @@ LL | fn foo(_: fn(u8) -> ());
| ------------ type in trait
...
LL | fn foo(_: fn(u16) -> ()) {}
| ^^^^^^^^^^^^^ expected `u8`, found `u16`
| ^^^^^^^^^^^^^
| |
| expected `u8`, found `u16`
| help: change the parameter type to match the trait: `fn(u8)`
|
= note: expected fn pointer `fn(fn(u8))`
found fn pointer `fn(fn(u16))`
@ -17,7 +20,10 @@ LL | fn bar(_: Option<u8>);
| ---------- type in trait
...
LL | fn bar(_: Option<u16>) {}
| ^^^^^^^^^^^ expected `u8`, found `u16`
| ^^^^^^^^^^^
| |
| expected `u8`, found `u16`
| help: change the parameter type to match the trait: `Option<u8>`
|
= note: expected fn pointer `fn(Option<u8>)`
found fn pointer `fn(Option<u16>)`
@ -29,7 +35,10 @@ LL | fn baz(_: (u8, u16));
| --------- type in trait
...
LL | fn baz(_: (u16, u16)) {}
| ^^^^^^^^^^ expected `u8`, found `u16`
| ^^^^^^^^^^
| |
| expected `u8`, found `u16`
| help: change the parameter type to match the trait: `(u8, u16)`
|
= note: expected fn pointer `fn((u8, _))`
found fn pointer `fn((u16, _))`