Files
rust/tests/ui/methods
bors 88638df1e7 Auto merge of #161827 - GuillaumeGomez:trait-mut-mismatch, r=mejrs
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
2026-09-21 22:48:22 +00:00
..
2026-07-09 23:34:43 +02:00
2026-07-18 18:57:06 +02:00
2026-06-01 14:13:08 +02:00
2026-07-15 23:38:07 +02:00
2026-03-28 16:18:11 +09:00
2026-03-28 16:18:11 +09:00
2026-06-07 00:13:04 +02:00
2026-07-15 23:38:07 +02:00
2025-09-23 08:02:54 +02:00
2025-05-31 19:49:19 +05:00