Files
rust/tests/ui/typeck
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-13 10:54:53 +02:00
2026-06-17 06:16:54 +02:00
2026-06-17 06:16:54 +02:00
2026-07-18 18:57:06 +02:00
2026-07-18 18:57:06 +02:00
2025-07-31 21:25:49 +05:00
2025-07-31 21:25:49 +05:00
2025-07-31 21:25:49 +05:00
2026-09-16 22:35:56 +00:00
2025-11-27 11:19:00 -05:00
2025-12-02 18:25:13 +00:00
2025-12-02 18:25:13 +00:00
2025-12-02 18:25:13 +00:00
2025-12-02 18:25:13 +00:00
2025-12-02 18:25:13 +00:00
2025-12-17 14:53:14 +00:00
2026-02-17 16:51:44 +00:00
2025-12-16 02:10:08 +09:00
2026-06-19 16:50:52 +02:00
2026-06-19 16:50:52 +02:00
2025-08-05 19:34:46 +05:00
2025-08-05 19:34:46 +05:00
2026-09-14 10:41:39 +03:00
2026-09-14 10:41:39 +03:00
2025-07-31 21:25:49 +05:00
2025-07-31 21:25:49 +05:00