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.
164 lines
8 KiB
Text
164 lines
8 KiB
Text
error: replacing an `Option` with `None`
|
|
--> tests/ui/mem_replace.rs:13:13
|
|
|
|
|
LL | let _ = mem::replace(&mut an_option, None);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
|
|
|
|
|
= note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]`
|
|
|
|
error: replacing an `Option` with `None`
|
|
--> tests/ui/mem_replace.rs:15:13
|
|
|
|
|
LL | let _ = mem::replace(an_option, None);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:20:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut s, String::default());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
|
|
|
|
|
= note: `-D clippy::mem-replace-with-default` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:21:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut s, String::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:24:13
|
|
|
|
|
LL | let _ = std::mem::replace(s, String::default());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:25:13
|
|
|
|
|
LL | let _ = std::mem::replace(s, String::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:26:13
|
|
|
|
|
LL | let _ = std::mem::replace(s, Default::default());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:29:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut v, Vec::default());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:30:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut v, Default::default());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:31:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut v, Vec::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:32:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut v, vec![]);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:35:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut hash_map, HashMap::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_map)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:38:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut btree_map, BTreeMap::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_map)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:41:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut vd, VecDeque::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut vd)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:44:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut hash_set, HashSet::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_set)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:47:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut btree_set, BTreeSet::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_set)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:50:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut list, LinkedList::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut list)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:53:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:56:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new()));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:59:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut refstr, "");
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut refstr)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:62:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut slice, &[]);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut slice)`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:98:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut s, String::default());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
|
|
|
|
error: replacing an `Option` with `None`
|
|
--> tests/ui/mem_replace.rs:128:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut f.0, None);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()`
|
|
|
|
error: replacing an `Option` with `None`
|
|
--> tests/ui/mem_replace.rs:129:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut *f, None);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()`
|
|
|
|
error: replacing an `Option` with `None`
|
|
--> tests/ui/mem_replace.rs:130:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut b.opt, None);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()`
|
|
|
|
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
|
|
--> tests/ui/mem_replace.rs:132:13
|
|
|
|
|
LL | let _ = std::mem::replace(&mut b.val, String::default());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)`
|
|
|
|
error: aborting due to 26 previous errors
|
|
|