Closed
Description
I tried this code (playground):
struct Foo;
trait Trait {
fn foo(&mut self);
}
impl Trait for Foo {
fn foo(&self) {}
}
I expected to see this happen: Diagnostic mentions an expected method type and a provided method type.
Instead, this happened: Diagnostic mentions that it expected a "fn pointer" of a different type:
error[E0053]: method `foo` has an incompatible type for trait
--> src/lib.rs:8:12
|
4 | fn foo(&mut self);
| --------- type in trait
...
8 | fn foo(&self) {}
| ^^^^^ types differ in mutability
|
= note: expected fn pointer `fn(&mut Foo)`
found fn pointer `fn(&Foo)`
help: consider change the type to match the mutability in trait
|
8 | fn foo(&mut self) {}
| ^^^^^^^^^
This was pretty confusing to me, because there are no function pointers in the code. It appears to be an implementation detail leaking through.
(There's also a typo in the help
note which I plan to fix in a separate PR)
cc #66389
Meta
rustc --version --verbose
:
1.51.0-nightly
(2021-01-10 c97f11af7bc4a6d3578f)