Skip to content

Commit c8df66f

Browse files
authored
Rollup merge of rust-lang#142822 - oli-obk:const-partial-eq, r=fee1-dead
Make `PartialEq` a `const_trait` r? ``@fee1-dead`` or ``@compiler-errors`` something generally useful but also required for rust-lang#142789
2 parents 7df08be + 9933442 commit c8df66f

25 files changed

+117
-606
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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@
33
#![allow(dead_code)]
44

55
const fn f(a: &u8, b: &u8) -> bool {
6+
//~^ HELP: add `#![feature(const_trait_impl)]` to the crate attributes to enable
7+
//~| HELP: add `#![feature(const_trait_impl)]` to the crate attributes to enable
8+
//~| HELP: add `#![feature(const_trait_impl)]` to the crate attributes to enable
69
a == b
7-
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
10+
//~^ ERROR: cannot call conditionally-const operator in constant functions
11+
//~| ERROR: `PartialEq` is not yet stable as a const trait
812
//~| HELP: consider dereferencing here
13+
//~| HELP: add `#![feature(const_trait_impl)]` to the crate attributes to enable
914
}
1015

1116
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
1217
a == b
13-
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
18+
//~^ ERROR: cannot call conditionally-const operator in constant functions
19+
//~| ERROR: `PartialEq` is not yet stable as a const trait
1420
//~| HELP: consider dereferencing here
21+
//~| HELP: add `#![feature(const_trait_impl)]` to the crate attributes to enable
1522
}
1623

1724
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
1825
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
1926
if l == r {
20-
//~^ ERROR: cannot call non-const operator in constant functions [E0015]
27+
//~^ ERROR: cannot call conditionally-const operator in constant functions
28+
//~| ERROR: `PartialEq` is not yet stable as a const trait
2129
//~| HELP: consider dereferencing here
30+
//~| HELP: add `#![feature(const_trait_impl)]` to the crate attributes to enable
2231
a = at;
2332
b = bt;
2433
} else {

tests/ui/consts/issue-90870.stderr

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,81 @@
1-
error[E0015]: cannot call non-const operator in constant functions
2-
--> $DIR/issue-90870.rs:6:5
1+
error[E0658]: cannot call conditionally-const operator in constant functions
2+
--> $DIR/issue-90870.rs:9:5
33
|
44
LL | a == b
55
| ^^^^^^
66
|
77
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
8+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
9+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
10+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
811
help: consider dereferencing here
912
|
1013
LL | *a == *b
1114
| + +
1215

13-
error[E0015]: cannot call non-const operator in constant functions
14-
--> $DIR/issue-90870.rs:12:5
16+
error: `PartialEq` is not yet stable as a const trait
17+
--> $DIR/issue-90870.rs:9:5
18+
|
19+
LL | a == b
20+
| ^^^^^^
21+
|
22+
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
23+
|
24+
LL + #![feature(const_trait_impl)]
25+
|
26+
27+
error[E0658]: cannot call conditionally-const operator in constant functions
28+
--> $DIR/issue-90870.rs:17:5
1529
|
1630
LL | a == b
1731
| ^^^^^^
1832
|
1933
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
34+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
35+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
36+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2037
help: consider dereferencing here
2138
|
2239
LL | ****a == ****b
2340
| ++++ ++++
2441

25-
error[E0015]: cannot call non-const operator in constant functions
26-
--> $DIR/issue-90870.rs:19:12
42+
error: `PartialEq` is not yet stable as a const trait
43+
--> $DIR/issue-90870.rs:17:5
44+
|
45+
LL | a == b
46+
| ^^^^^^
47+
|
48+
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
49+
|
50+
LL + #![feature(const_trait_impl)]
51+
|
52+
53+
error[E0658]: cannot call conditionally-const operator in constant functions
54+
--> $DIR/issue-90870.rs:26:12
2755
|
2856
LL | if l == r {
2957
| ^^^^^^
3058
|
3159
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
60+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
61+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
62+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3263
help: consider dereferencing here
3364
|
3465
LL | if *l == *r {
3566
| + +
3667

37-
error: aborting due to 3 previous errors
68+
error: `PartialEq` is not yet stable as a const trait
69+
--> $DIR/issue-90870.rs:26:12
70+
|
71+
LL | if l == r {
72+
| ^^^^^^
73+
|
74+
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
75+
|
76+
LL + #![feature(const_trait_impl)]
77+
|
78+
79+
error: aborting due to 6 previous errors
3880

39-
For more information about this error, try `rustc --explain E0015`.
81+
For more information about this error, try `rustc --explain E0658`.

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

0 commit comments

Comments
 (0)