Skip to content

Commit e8ac838

Browse files
committed
small nits
1 parent d090b1a commit e8ac838

5 files changed

Lines changed: 21 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
- Add `Hash` derive similar to `std`'s one, but considering generics correctly,
1212
and supporting custom hash functions per field or skipping fields.
1313
([#532](https://github.com/JelteF/derive_more/pull/532))
14-
- Add support for custom eq functions in `PartialEq` derive.
14+
- Add support for custom eq functions in `PartialEq`/`Eq` derive.
1515
([#535](https://github.com/JelteF/derive_more/pull/535))
1616

1717
### Fixed

impl/doc/eq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl PartialEq for Enum {
289289

290290
### Custom comparison with `with`
291291

292-
Both `#[eq(with(...))]` and `#[partial_eq(with(...))]` attribute allows specifying a custom comparison function
292+
Both `#[eq(with(...))]` and `#[partial_eq(with(...))]` attributes allows specifying a custom comparison function
293293
for a field. The function must have the signature `fn(&T, &T) -> bool` where `T` is the field type.
294294

295295
```rust
@@ -340,4 +340,4 @@ impl PartialEq for Foo {
340340
}
341341
}
342342
}
343-
```
343+
```

impl/src/cmp/partial_eq.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ impl StructuralExpansion<'_> {
215215
let maybe_not = (!eq).then(|| quote! {!});
216216
quote! { #maybe_not #eq_fn(#self_val, #other_val) }
217217
}
218-
).unwrap_or_else(||
219-
quote! { #self_val #cmp #other_val }
218+
).unwrap_or_else(|| quote! { #self_val #cmp #other_val }
220219
);
221220
punctuated::Pair::Punctuated(equality, &chain)
222221
})
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
#[derive(derive_more::PartialEq)]
22
struct Foo(#[partial_eq(with(unknown))] i32);
33

4-
fn incompatible_types(a:& str) ->i32 {0}
4+
fn incompatible_types(_a: &str) ->i32 {0}
55

66
#[derive(derive_more::PartialEq)]
77
struct Bar(#[partial_eq(with(incompatible_types))] i32);
88

9-
109
#[derive(derive_more::PartialEq)]
1110
enum Enum {
1211
Bar { #[partial_eq(with(unknown))] i: i32 },
1312
Baz { #[partial_eq(with(incompatible_types))] i: i32 },
1413
}
1514

16-
17-
1815
fn main() {}

tests/compile_fail/partial_eq/unknown_with_function.stderr

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
2020
note: function defined here
2121
--> tests/compile_fail/partial_eq/unknown_with_function.rs:4:4
2222
|
23-
4 | fn incompatible_types(a:& str) ->i32 {0}
24-
| ^^^^^^^^^^^^^^^^^^ -------
23+
4 | fn incompatible_types(_a: &str) ->i32 {0}
24+
| ^^^^^^^^^^^^^^^^^^ --------
2525

2626
error[E0308]: mismatched types
2727
--> tests/compile_fail/partial_eq/unknown_with_function.rs:6:10
@@ -35,46 +35,38 @@ error[E0308]: mismatched types
3535
= note: this error originates in the derive macro `derive_more::PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

3737
error[E0425]: cannot find function `unknown` in this scope
38-
--> tests/compile_fail/partial_eq/unknown_with_function.rs:12:29
38+
--> tests/compile_fail/partial_eq/unknown_with_function.rs:11:29
3939
|
40-
12 | Bar { #[partial_eq(with(unknown))] i: i32 },
40+
11 | Bar { #[partial_eq(with(unknown))] i: i32 },
4141
| ^^^^^^^ not found in this scope
4242

4343
error[E0061]: this function takes 1 argument but 2 arguments were supplied
44-
--> tests/compile_fail/partial_eq/unknown_with_function.rs:13:29
44+
--> tests/compile_fail/partial_eq/unknown_with_function.rs:12:29
4545
|
46-
10 | #[derive(derive_more::PartialEq)]
46+
9 | #[derive(derive_more::PartialEq)]
4747
| ----------------------
4848
| |
4949
| expected `&str`, found `&i32`
5050
| unexpected argument #2 of type `&i32`
5151
...
52-
13 | Baz { #[partial_eq(with(incompatible_types))] i: i32 },
52+
12 | Baz { #[partial_eq(with(incompatible_types))] i: i32 },
5353
| ^^^^^^^^^^^^^^^^^^
5454
|
5555
= note: expected reference `&str`
5656
found reference `&i32`
5757
note: function defined here
5858
--> tests/compile_fail/partial_eq/unknown_with_function.rs:4:4
5959
|
60-
4 | fn incompatible_types(a:& str) ->i32 {0}
61-
| ^^^^^^^^^^^^^^^^^^ -------
60+
4 | fn incompatible_types(_a: &str) ->i32 {0}
61+
| ^^^^^^^^^^^^^^^^^^ --------
6262

6363
error[E0308]: mismatched types
64-
--> tests/compile_fail/partial_eq/unknown_with_function.rs:10:10
65-
|
66-
10 | #[derive(derive_more::PartialEq)]
67-
| ^^^^^^^^^^^^^^^^^^^^^^
68-
| |
69-
| expected `bool`, found `i32`
70-
| expected `bool` because of return type
71-
|
72-
= note: this error originates in the derive macro `derive_more::PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
73-
74-
warning: unused variable: `a`
75-
--> tests/compile_fail/partial_eq/unknown_with_function.rs:4:23
64+
--> tests/compile_fail/partial_eq/unknown_with_function.rs:9:10
7665
|
77-
4 | fn incompatible_types(a:& str) ->i32 {0}
78-
| ^ help: if this is intentional, prefix it with an underscore: `_a`
66+
9 | #[derive(derive_more::PartialEq)]
67+
| ^^^^^^^^^^^^^^^^^^^^^^
68+
| |
69+
| expected `bool`, found `i32`
70+
| expected `bool` because of return type
7971
|
80-
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
72+
= note: this error originates in the derive macro `derive_more::PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)