Skip to content

Commit 03c057d

Browse files
committed
Make PartialEq a const_trait
1 parent 886ab07 commit 03c057d

25 files changed

+57
-641
lines changed

library/core/src/cmp.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ use crate::ops::ControlFlow;
247247
append_const_msg
248248
)]
249249
#[rustc_diagnostic_item = "PartialEq"]
250+
#[const_trait]
251+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
250252
pub trait PartialEq<Rhs: PointeeSized = Self>: PointeeSized {
251253
/// Tests for `self` and `other` values to be equal, and is used by `==`.
252254
#[must_use]
@@ -1811,7 +1813,8 @@ mod impls {
18111813
macro_rules! partial_eq_impl {
18121814
($($t:ty)*) => ($(
18131815
#[stable(feature = "rust1", since = "1.0.0")]
1814-
impl PartialEq for $t {
1816+
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
1817+
impl const PartialEq for $t {
18151818
#[inline]
18161819
fn eq(&self, other: &Self) -> bool { *self == *other }
18171820
#[inline]
@@ -2018,9 +2021,10 @@ mod impls {
20182021
// & pointers
20192022

20202023
#[stable(feature = "rust1", since = "1.0.0")]
2021-
impl<A: PointeeSized, B: PointeeSized> PartialEq<&B> for &A
2024+
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2025+
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&B> for &A
20222026
where
2023-
A: PartialEq<B>,
2027+
A: ~const PartialEq<B>,
20242028
{
20252029
#[inline]
20262030
fn eq(&self, other: &&B) -> bool {
@@ -2089,9 +2093,10 @@ mod impls {
20892093
// &mut pointers
20902094

20912095
#[stable(feature = "rust1", since = "1.0.0")]
2092-
impl<A: PointeeSized, B: PointeeSized> PartialEq<&mut B> for &mut A
2096+
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2097+
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&mut B> for &mut A
20932098
where
2094-
A: PartialEq<B>,
2099+
A: ~const PartialEq<B>,
20952100
{
20962101
#[inline]
20972102
fn eq(&self, other: &&mut B) -> bool {
@@ -2158,9 +2163,10 @@ mod impls {
21582163
impl<A: PointeeSized> Eq for &mut A where A: Eq {}
21592164

21602165
#[stable(feature = "rust1", since = "1.0.0")]
2161-
impl<A: PointeeSized, B: PointeeSized> PartialEq<&mut B> for &A
2166+
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2167+
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&mut B> for &A
21622168
where
2163-
A: PartialEq<B>,
2169+
A: ~const PartialEq<B>,
21642170
{
21652171
#[inline]
21662172
fn eq(&self, other: &&mut B) -> bool {
@@ -2173,9 +2179,10 @@ mod impls {
21732179
}
21742180

21752181
#[stable(feature = "rust1", since = "1.0.0")]
2176-
impl<A: PointeeSized, B: PointeeSized> PartialEq<&B> for &mut A
2182+
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2183+
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&B> for &mut A
21772184
where
2178-
A: PartialEq<B>,
2185+
A: ~const PartialEq<B>,
21792186
{
21802187
#[inline]
21812188
fn eq(&self, other: &&B) -> bool {

tests/ui/consts/const_cmp_type_id.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ use std::any::TypeId;
66
fn main() {
77
const {
88
assert!(TypeId::of::<u8>() == TypeId::of::<u8>());
9-
//~^ ERROR cannot call non-const operator in constants
9+
//~^ ERROR the trait bound `TypeId: const PartialEq` is not satisfied
1010
assert!(TypeId::of::<()>() != TypeId::of::<u8>());
11-
//~^ ERROR cannot call non-const operator in constants
11+
//~^ ERROR the trait bound `TypeId: const PartialEq` is not satisfied
1212
let _a = TypeId::of::<u8>() < TypeId::of::<u16>();
13-
//~^ ERROR cannot call non-const operator in constants
1413
// can't assert `_a` because it is not deterministic
1514
// FIXME(const_trait_impl) make it pass
1615
}
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1-
error[E0015]: cannot call non-const operator in constants
1+
error[E0277]: the trait bound `TypeId: const PartialEq` is not satisfied
22
--> $DIR/const_cmp_type_id.rs:8:17
33
|
44
LL | assert!(TypeId::of::<u8>() == TypeId::of::<u8>());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
note: impl defined here, but it is not `const`
8-
--> $SRC_DIR/core/src/any.rs:LL:COL
9-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
106

11-
error[E0015]: cannot call non-const operator in constants
7+
error[E0277]: the trait bound `TypeId: const PartialEq` is not satisfied
128
--> $DIR/const_cmp_type_id.rs:10:17
139
|
1410
LL | assert!(TypeId::of::<()>() != TypeId::of::<u8>());
1511
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16-
|
17-
note: impl defined here, but it is not `const`
18-
--> $SRC_DIR/core/src/any.rs:LL:COL
19-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
20-
21-
error[E0015]: cannot call non-const operator in constants
22-
--> $DIR/const_cmp_type_id.rs:12:18
23-
|
24-
LL | let _a = TypeId::of::<u8>() < TypeId::of::<u16>();
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26-
|
27-
note: impl defined here, but it is not `const`
28-
--> $SRC_DIR/core/src/any.rs:LL:COL
29-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
3012

31-
error: aborting due to 3 previous errors
13+
error: aborting due to 2 previous errors
3214

33-
For more information about this error, try `rustc --explain E0015`.
15+
For more information about this error, try `rustc --explain E0277`.

tests/ui/consts/fn_trait_refs.stderr

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ error[E0635]: unknown feature `const_fn_trait_ref_impls`
44
LL | #![feature(const_fn_trait_ref_impls)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error[E0635]: unknown feature `const_cmp`
8-
--> $DIR/fn_trait_refs.rs:7:12
9-
|
10-
LL | #![feature(const_cmp)]
11-
| ^^^^^^^^^
12-
137
error: `~const` can only be applied to `#[const_trait]` traits
148
--> $DIR/fn_trait_refs.rs:14:8
159
|
@@ -155,21 +149,17 @@ note: `FnMut` can't be used with `~const` because it isn't annotated with `#[con
155149
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
156150
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
157151

158-
error[E0015]: cannot call non-const operator in constants
152+
error[E0277]: the trait bound `(i32, i32, i32): const PartialEq` is not satisfied
159153
--> $DIR/fn_trait_refs.rs:71:17
160154
|
161155
LL | assert!(test_one == (1, 1, 1));
162156
| ^^^^^^^^^^^^^^^^^^^^^
163-
|
164-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
165157

166-
error[E0015]: cannot call non-const operator in constants
158+
error[E0277]: the trait bound `(i32, i32): const PartialEq` is not satisfied
167159
--> $DIR/fn_trait_refs.rs:74:17
168160
|
169161
LL | assert!(test_two == (2, 2));
170162
| ^^^^^^^^^^^^^^^^^^
171-
|
172-
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
173163

174164
error[E0015]: cannot call non-const closure in constant functions
175165
--> $DIR/fn_trait_refs.rs:16:5
@@ -195,7 +185,7 @@ LL | f()
195185
|
196186
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
197187

198-
error: aborting due to 22 previous errors
188+
error: aborting due to 21 previous errors
199189

200-
Some errors have detailed explanations: E0015, E0635.
190+
Some errors have detailed explanations: E0015, E0277, E0635.
201191
For more information about an error, try `rustc --explain E0015`.
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
error[E0015]: cannot call non-const operator in constant functions
1+
error[E0277]: the trait bound `TypeId: ~const PartialEq` is not satisfied
22
--> $DIR/issue-73976-monomorphic.rs:21:5
33
|
44
LL | GetTypeId::<T>::VALUE == GetTypeId::<usize>::VALUE
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
note: impl defined here, but it is not `const`
8-
--> $SRC_DIR/core/src/any.rs:LL:COL
9-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
106

117
error: aborting due to 1 previous error
128

13-
For more information about this error, try `rustc --explain E0015`.
9+
For more information about this error, try `rustc --explain E0277`.

tests/ui/consts/issue-90870.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
// Regression test for issue #90870.
2-
2+
//@ check-pass
3+
#![feature(const_trait_impl)]
34
#![allow(dead_code)]
45

56
const fn f(a: &u8, b: &u8) -> bool {
67
a == b
7-
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
8-
//~| HELP: consider dereferencing here
98
}
109

1110
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
1211
a == b
13-
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
14-
//~| HELP: consider dereferencing here
1512
}
1613

1714
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
1815
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
1916
if l == r {
20-
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
21-
//~| HELP: consider dereferencing here
2217
a = at;
2318
b = bt;
2419
} else {

tests/ui/consts/issue-90870.stderr

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/ui/traits/const-traits/call-const-trait-method-pass.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//@ known-bug: #110395
2-
31
#![feature(const_trait_impl, const_ops)]
2+
//@ check-pass
43

54
struct Int(i32);
65

tests/ui/traits/const-traits/call-const-trait-method-pass.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/ui/traits/const-traits/call-generic-in-impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//@ known-bug: #110395
2-
// FIXME(const_trait_impl) check-pass
1+
//@ check-pass
32
#![feature(const_trait_impl)]
43

54
#[const_trait]

tests/ui/traits/const-traits/call-generic-in-impl.stderr

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/ui/traits/const-traits/call-generic-method-chain.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Basic test for calling methods on generic type parameters in `const fn`.
22
3-
//@ known-bug: #110395
43
//@ compile-flags: -Znext-solver
5-
// FIXME(const_trait_impl) check-pass
4+
//@ check-pass
65

76
#![feature(const_trait_impl)]
87

tests/ui/traits/const-traits/call-generic-method-chain.stderr

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)