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-09-20 04:11:09 +00:00
2025-12-02 18:25:13 +00:00
2025-07-29 10:32:15 +02:00
2025-07-29 10:32:15 +02:00
2025-10-18 01:20:25 +00:00
2025-10-11 21:59:51 -04:00
2025-10-11 21:59:51 -04:00
2025-12-02 18:25:13 +00:00
2026-05-02 21:07:23 +08:00
2026-05-02 21:07:23 +08: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
2026-01-26 17:34:31 +00:00
2025-10-01 07:39:03 +00:00
2025-07-10 17:23:29 +00:00
2026-05-23 12:53:44 +08:00
2025-07-29 10:32:15 +02:00
2026-03-28 16:18:11 +09:00
2026-03-28 16:18:11 +09:00
2026-03-28 16:18:11 +09:00
2026-03-28 16:18:11 +09:00
2026-04-09 11:36:46 +02:00
2026-04-09 11:36:46 +02:00
2025-10-31 20:44:01 +00:00
2025-07-31 21:25:49 +05:00
2025-07-31 21:25:49 +05:00
2026-04-13 22:26:05 +02:00
2025-08-17 13:01:02 -04:00
2025-12-02 18:25:13 +00:00
2025-08-02 15:29:16 -04:00
2025-08-02 15:29:16 -04:00
2026-04-03 17:30:57 +01:00
2026-04-03 17:30:57 +01:00
2026-02-25 05:51:37 +00:00
2025-09-26 15:33:48 +02:00
2025-09-26 15:33:48 +02:00
2025-07-31 21:25:49 +05:00
2025-07-31 21:25:49 +05:00
2026-04-20 22:21:51 +08:00
2026-02-16 19:36:09 +00:00
2026-02-16 19:36:09 +00:00
2026-09-16 22:35:56 +00:00
2025-11-27 11:19:00 -05:00
2026-09-21 15:20:26 +02:00
2026-01-13 01:16:58 +00:00
2025-09-29 03:28:52 +00:00
2025-12-10 19:27:40 +00:00
2026-09-20 04:11:09 +00:00
2025-12-02 18:25:13 +00:00
2026-08-13 14:12:34 +02:00
2026-07-21 01:03:16 +03:00
2026-07-21 01:03:16 +03:00
2025-12-10 23:41:19 +00:00
2026-08-13 14:12:34 +02:00
2026-08-13 14:12:34 +02:00
2026-03-21 02:24:36 +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
2026-07-18 18:42:03 +02:00
2025-07-18 20:34:58 +08:00
2025-09-29 03:28:52 +00:00
2025-12-02 18:25:13 +00:00
2025-12-17 14:53:14 +00:00
2026-07-13 22:48:25 +00:00
2026-01-26 17:34:31 +00:00
2026-05-31 04:04:30 +05:30
2026-08-13 14:12:34 +02:00
2026-09-20 04:11:09 +00:00
2026-08-13 11:44:34 +08:00
2026-08-13 11:44:34 +08:00
2026-08-13 11:44:34 +08:00
2026-02-17 16:51:44 +00:00
2026-02-17 16:51:44 +00:00
2026-04-09 14:37:09 +00:00
2026-04-09 14:37:09 +00:00
2026-06-18 05:28:05 +02:00
2026-07-14 23:21:50 +02:00
2026-09-20 17:36:00 +00:00
2025-10-18 01:20:25 +00:00
2025-07-13 00:03:31 +05:00
2025-07-13 00:03:31 +05:00
2025-12-16 02:10:08 +09:00
2025-12-16 02:10:08 +09:00
2025-07-05 00:45:24 +05:00
2025-12-08 07:06:13 +09:00
2025-12-08 07:06:13 +09:00
2025-12-02 18:25:13 +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
2026-08-17 20:41:21 +03:30
2026-08-17 20:41:21 +03:30
2026-02-17 16:51:44 +00:00
2026-02-17 16:51:44 +00:00
2026-02-17 16:51:44 +00:00
2025-10-05 17:45:24 +00:00
2025-10-05 17:45:27 +00:00
2025-11-28 21:40:53 +09:00
2025-11-28 21:40:53 +09:00
2026-05-31 04:04:30 +05:30
2025-12-16 02:10:08 +09:00
2025-12-16 02:10:08 +09:00
2025-10-18 23:45:19 +09:00
2025-10-18 23:45:19 +09:00
2025-09-12 14:45:12 -04:00
2025-09-12 14:45:12 -04:00
2026-09-19 19:52:47 +00:00
2026-09-19 19:52:47 +00:00
2026-08-03 21:40:22 +01:00
2026-08-03 21:40:22 +01:00
2025-08-05 19:34:46 +05:00
2025-08-05 19:34:46 +05:00
2026-03-09 09:11:06 +00:00
2026-03-09 09:11:06 +00:00
2025-12-02 18:25:13 +00:00
2026-09-20 04:11:09 +00:00
2025-08-31 10:55:14 +08:00
2025-08-31 10:55:14 +08:00
2026-07-13 10:54:53 +02:00
2026-03-28 16:18:11 +09:00
2025-07-13 00:03:31 +05:00
2025-07-13 00:03:31 +05:00
2026-01-05 15:35:01 +09:00
2025-10-11 21:59:51 -04:00
2025-10-11 21:59:51 -04:00
2026-08-12 14:04:31 +06:00
2026-09-20 17:36:00 +00:00
2026-03-04 08:06:45 +08:00
2025-09-29 03:28:52 +00:00
2026-09-14 10:41:39 +03:00
2026-09-14 10:41:39 +03:00
2025-08-22 17:55:15 +00:00
2026-09-20 16:17:20 +08:00
2026-06-20 22:37:27 +02:00
2026-06-20 22:37:27 +02:00
2026-09-20 16:17:20 +08:00
2026-05-31 03:40:38 +02:00
2026-05-31 03:40:38 +02:00
2025-07-31 21:25:49 +05:00
2026-03-29 21:07:54 +00:00
2025-08-10 11:54:15 -04:00
2025-08-10 11:54:15 -04:00
2025-07-31 21:25:49 +05:00