Commit graph

11 commits

Author SHA1 Message Date
Esteban Küber
39d73d5bbb Use MIR body to identify more "default equivalent" calls
When looking for `Default` impls that could be derived, we look at the
body of their `fn default()` and if it is an fn call or literal we check
if they are equivalent to what `#[derive(Default)]` would have used.

Now, when checking those fn calls in the `fn default()` body, we also
compare against the corresponding type's `Default::default` body to see
if our call is equivalent to that one.

For example, given

```rust
struct S;

impl S {
    fn new() -> S { S }
}

impl Default for S {
    fn default() -> S { S::new() }
}
```

`<S as Default>::default()` and `S::new()` are considered equivalent.
Given that, if the user also writes

```rust
struct R {
    s: S,
}

impl Default for R {
    fn default() -> R {
        R { s: S::new() }
    }
}
```

the `derivable_impls` lint will now trigger.
2025-02-11 02:59:06 +00:00
Scott Gerring
9f7fb41272 fix: multipart suggestions for derivable_impls 2024-11-22 14:17:45 +01:00
Oli Scherer
3b390d416d Bump clippy version 2024-07-15 08:51:04 +00:00
clubby789
aa1c9a5993 If suggestion would leave an empty line, delete it 2024-03-01 13:48:20 +00:00
Philipp Krones
471469d30f Merge commit '98363cbf6a' into clippyup 2023-09-12 18:44:06 +02:00
Philipp Krones
cc61aeea54 Merge commit '080b587854' into clippyup 2023-08-24 21:32:12 +02:00
Philipp Krones
cb3ecf7b79 Merge commit '37f4c1725d' into clippyup 2023-07-02 14:59:02 +02:00
Philipp Krones
a1b75c5108 Merge commit 'a3ed905928' into clippyup 2023-04-23 13:28:56 +02:00
Philipp Krones
cf8a67d9ad Merge commit '3c06e0b1ce' into clippyup 2023-03-10 10:53:50 +01:00
Philipp Krones
d21616737b Merge commit '7f27e2e74e' into clippyup 2023-01-12 19:48:13 +01:00
David Koloski
4d015293d1 Merge commit '7248d06384' into sync-from-clippy 2022-09-21 13:13:27 -04:00