diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2025-02-11 03:50:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-11 03:50:55 +0000 |
| commit | ff87bead4f4931de38194809b5c9a420cce732e6 (patch) | |
| tree | 0f76172a02c14de9c17a8941cb02359523e31327 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp | |
| parent | b7ec4c13f34dae4a2309f5dcc074e149b36ea81b (diff) | |
| parent | 39d73d5bbb3118382474f3df82b8c156d29fff01 (diff) | |
| download | rust-ff87bead4f4931de38194809b5c9a420cce732e6.tar.gz rust-ff87bead4f4931de38194809b5c9a420cce732e6.zip | |
Use MIR body to identify more "default equivalent" calls for `derivable_impls` (#13988)
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.
changelog: [`derivable_impls`]: detect when a `Default` impl is using
the same fn call that that type's `Default::default` calls
changelog: [`mem_replace_with_default`]: detect when `std::mem::replace`
is being called with the same fn that that type's `Default::default`
calls, without the need of a manually maintained list
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
