Skip to content

Commit bd8b47d

Browse files
committed
Do not add leading asterisk in the PartialEq
Adding leading asterisk can cause compilation failure for the _types_ that don't implement the `Copy`.
1 parent 13e63f7 commit bd8b47d

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn expand_deriving_partial_eq(
3131
};
3232

3333
// We received arguments of type `&T`. Convert them to type `T` by stripping
34-
// any leading `&` or adding `*`. This isn't necessary for type checking, but
34+
// any leading `&`. This isn't necessary for type checking, but
3535
// it results in better error messages if something goes wrong.
3636
//
3737
// Note: for arguments that look like `&{ x }`, which occur with packed
@@ -53,8 +53,7 @@ pub fn expand_deriving_partial_eq(
5353
inner.clone()
5454
}
5555
} else {
56-
// No leading `&`: add a leading `*`.
57-
cx.expr_deref(field.span, expr.clone())
56+
expr.clone()
5857
}
5958
};
6059
cx.expr_binary(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
3+
trait Animal {
4+
fn noise(&self) -> String;
5+
}
6+
7+
impl PartialEq for dyn Animal {
8+
fn eq(&self, other: &Self) -> bool {
9+
self.noise() == other.noise()
10+
}
11+
}
12+
13+
#[derive(PartialEq)]
14+
enum Monkey {
15+
Baboon(Box<dyn Animal>),
16+
}
17+
18+
fn main() {}

tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `==` cannot be applied to type `Error`
1+
error[E0369]: binary operation `==` cannot be applied to type `&Error`
22
--> $DIR/derives-span-PartialEq-enum-struct-variant.rs:9:6
33
|
44
LL | #[derive(PartialEq)]

tests/ui/derives/derives-span-PartialEq-enum.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `==` cannot be applied to type `Error`
1+
error[E0369]: binary operation `==` cannot be applied to type `&Error`
22
--> $DIR/derives-span-PartialEq-enum.rs:9:6
33
|
44
LL | #[derive(PartialEq)]

tests/ui/deriving/deriving-all-codegen.stdout

+8-8
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ impl ::core::cmp::PartialEq for Enum1 {
876876
fn eq(&self, other: &Enum1) -> bool {
877877
match (self, other) {
878878
(Enum1::Single { x: __self_0 }, Enum1::Single { x: __arg1_0 }) =>
879-
*__self_0 == *__arg1_0,
879+
__self_0 == __arg1_0,
880880
}
881881
}
882882
}
@@ -1119,10 +1119,10 @@ impl ::core::cmp::PartialEq for Mixed {
11191119
__self_discr == __arg1_discr &&
11201120
match (self, other) {
11211121
(Mixed::R(__self_0), Mixed::R(__arg1_0)) =>
1122-
*__self_0 == *__arg1_0,
1122+
__self_0 == __arg1_0,
11231123
(Mixed::S { d1: __self_0, d2: __self_1 }, Mixed::S {
11241124
d1: __arg1_0, d2: __arg1_1 }) =>
1125-
*__self_0 == *__arg1_0 && *__self_1 == *__arg1_1,
1125+
__self_0 == __arg1_0 && __self_1 == __arg1_1,
11261126
_ => true,
11271127
}
11281128
}
@@ -1245,11 +1245,11 @@ impl ::core::cmp::PartialEq for Fielded {
12451245
__self_discr == __arg1_discr &&
12461246
match (self, other) {
12471247
(Fielded::X(__self_0), Fielded::X(__arg1_0)) =>
1248-
*__self_0 == *__arg1_0,
1248+
__self_0 == __arg1_0,
12491249
(Fielded::Y(__self_0), Fielded::Y(__arg1_0)) =>
1250-
*__self_0 == *__arg1_0,
1250+
__self_0 == __arg1_0,
12511251
(Fielded::Z(__self_0), Fielded::Z(__arg1_0)) =>
1252-
*__self_0 == *__arg1_0,
1252+
__self_0 == __arg1_0,
12531253
_ => unsafe { ::core::intrinsics::unreachable() }
12541254
}
12551255
}
@@ -1368,9 +1368,9 @@ impl<T: ::core::cmp::PartialEq, U: ::core::cmp::PartialEq>
13681368
__self_discr == __arg1_discr &&
13691369
match (self, other) {
13701370
(EnumGeneric::One(__self_0), EnumGeneric::One(__arg1_0)) =>
1371-
*__self_0 == *__arg1_0,
1371+
__self_0 == __arg1_0,
13721372
(EnumGeneric::Two(__self_0), EnumGeneric::Two(__arg1_0)) =>
1373-
*__self_0 == *__arg1_0,
1373+
__self_0 == __arg1_0,
13741374
_ => unsafe { ::core::intrinsics::unreachable() }
13751375
}
13761376
}

0 commit comments

Comments
 (0)