Fix suggestion for mutability mismatch between trait def and trait impl in 2015 edition
This code:
```rust
mod bar {
pub struct X;
}
pub trait A {
fn f(x: &mut bar::X);
}
mod b {
pub struct X;
impl crate::A for X {
fn f(_x: &crate::bar::X) {}
}
}
```
emits:
```console
error[E0053]: method `f` has an incompatible type for trait
--> foo.rs:13:18
|
13 | fn f(_x: &crate::bar::X) {}
| ^^^^^^^^^^^^^^ types differ in mutability
|
note: type in trait
--> foo.rs:6:13
|
6 | fn f(x: &mut bar::X);
| ^^^^^^^^^^^
= note: expected signature `fn(&mut X)`
found signature `fn(&X)`
help: change the parameter type to match the trait
|
13 - fn f(_x: &crate::bar::X) {}
13 + fn f(_x: &mut bar::X) {}
|
```
Which is wrong. This PR fixes it. However the `Ty` doesn't hold a context (or at least not a correct one) allowing to have a correct path to the `X` type. So instead, in case of a mutability mismatch, we (try to) retrieve the code snippet, and remove/add the `mut` keyword. If we fail to, we revert to the current behaviour.
r? @mejrs