Commit graph

16 commits

Author SHA1 Message Date
Guillaume Gomez
1f94d55a18 Fix new tests updates 2025-02-15 13:38:42 +01:00
Guillaume Gomez
f666fd6417 Update UI tests 2025-02-15 13:38:16 +01:00
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
mojave2
90fcc67d32
fix "derivable_impls: attributes are ignored" 2023-08-25 19:15:44 +08:00
Oli Scherer
3d88fae050 Update ui test crate 2023-08-11 14:02:28 +00:00
y21
2ba1926955 [derivable_impls]: don't lint if expr unsize-coerces 2023-06-14 16:52:02 +02:00
Oli Scherer
def1705a27 Update to a compiletest-rs version that requires //@ for commands 2023-04-20 14:44:03 +00:00
Samuel Tardieu
c82ff00539 Do not suggest to derive Default on generics with implicit arguments 2023-02-26 15:44:04 +01:00
Kyle Huey
1c42dbba60 Expand derivable-impls to cover enums with a default unit variant. 2023-01-04 19:08:37 -08:00
kraktus
6f13203b2d Make derivable_impls machine applicable 2022-09-13 17:00:19 +02:00
hkalbasi
ea8e65f0da exclude enum from derivable impls 2021-10-03 11:58:27 +03:30
surechen
a3d3735515 Arrays of sizes from 0 to 32 (inclusive) implement [Default] trait, edit method is_default_equivalent() to satisfy with this. 2021-09-30 10:41:36 +08:00
hamidreza kalbasi
5aff720e1a fix derivable impl false positives 2021-09-10 19:49:02 +04:30
hamidreza kalbasi
8221f9e795 add derivable impls lint 2021-09-05 01:25:59 +04:30