Skip to content

Commit

Permalink
Restore const PartialEq
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Dec 6, 2023
1 parent 2896841 commit 268d5f3
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 111 deletions.
12 changes: 12 additions & 0 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ use self::Ordering::*;
append_const_msg
)]
#[rustc_diagnostic_item = "PartialEq"]
#[cfg_attr(not(bootstrap), const_trait)]
pub trait PartialEq<Rhs: ?Sized = Self> {
/// This method tests for `self` and `other` values to be equal, and is used
/// by `==`.
Expand Down Expand Up @@ -1414,12 +1415,23 @@ mod impls {
macro_rules! partial_eq_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(bootstrap)]
impl PartialEq for $t {
#[inline]
fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
#[inline]
fn ne(&self, other: &$t) -> bool { (*self) != (*other) }
}

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
#[cfg(not(bootstrap))]
impl const PartialEq for $t {
#[inline]
fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
#[inline]
fn ne(&self, other: &$t) -> bool { (*self) != (*other) }
}
)*)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// known-bug: #110395
// check-pass
#![feature(const_trait_impl)]

#[const_trait]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Basic test for calling methods on generic type parameters in `const fn`.

// known-bug: #110395
// check-pass

#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

struct S;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// known-bug: #110395
// check-pass

#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

struct S;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// FIXME(effects)
// check-pass
#![feature(const_trait_impl, effects)]

pub const fn equals_self<T: PartialEq>(t: &T) -> bool {
*t == *t
// (remove this) ~^ ERROR can't compare
//~^ ERROR mismatched types
// FIXME(effects): diagnostic
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0308]: mismatched types
--> $DIR/call-generic-method-fail.rs:4:5
|
LL | *t == *t
| ^^^^^^^^ expected `host`, found `true`
|
= note: expected constant `host`
found constant `true`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Basic test for calling methods on generic type parameters in `const fn`.

// known-bug: #110395
// check-pass

#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

struct S;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(
associated_type_bounds,
const_trait_impl,
effects,
const_cmp,
)]

Expand Down
43 changes: 10 additions & 33 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,39 +1,16 @@
error[E0635]: unknown feature `const_cmp`
--> $DIR/const-impl-trait.rs:6:5
error[E0277]: can't compare `impl PartialEq + Destruct + Copy` with `impl PartialEq + Destruct + Copy`
--> $DIR/const-impl-trait.rs:28:17
|
LL | const_cmp,
| ^^^^^^^^^

error: ~const can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:11:30
|
LL | const fn cmp(a: &impl ~const PartialEq) -> bool {
| ^^^^^^^^^

error: ~const can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:15:30
|
LL | const fn wrap(x: impl ~const PartialEq + ~const Destruct)
| ^^^^^^^^^

error: ~const can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:16:20
LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `impl PartialEq + Destruct + Copy == impl PartialEq + Destruct + Copy`
|
LL | -> impl ~const PartialEq + ~const Destruct
| ^^^^^^^^^

error: ~const can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:23:29
= help: the trait `PartialEq<impl PartialEq + Destruct + Copy>` is not implemented for `impl PartialEq + Destruct + Copy`
note: required by a bound in `Foo::{opaque#0}`
--> $DIR/const-impl-trait.rs:24:22
|
LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy;
| ^^^^^^^^^

error: ~const can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:27:29
|
LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy {
| ^^^^^^^^^
| ^^^^^^^^^^^^^^^^ required by this bound in `Foo::{opaque#0}`

error: aborting due to 6 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0635`.
For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// known-bug: #110395
#![feature(const_trait_impl, const_cmp, const_default_impls, derive_const)]
// check-pass
#![feature(const_trait_impl, const_cmp, const_default_impls, derive_const, effects)]

pub struct A;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
error[E0635]: unknown feature `const_cmp`
--> $DIR/derive-const-use.rs:2:30
|
LL | #![feature(const_trait_impl, const_cmp, const_default_impls, derive_const)]
| ^^^^^^^^^

error[E0635]: unknown feature `const_default_impls`
--> $DIR/derive-const-use.rs:2:41
--> $DIR/derive-const-use.rs:3:5
|
LL | #![feature(const_trait_impl, const_cmp, const_default_impls, derive_const)]
| ^^^^^^^^^^^^^^^^^^^
LL | const_default_impls, derive_const)]
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0635`.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// known-bug: #110395
// check-pass

#![feature(derive_const)]
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

#[derive_const(PartialEq)]
pub struct Reverse<T>(T);
Expand Down

This file was deleted.

0 comments on commit 268d5f3

Please sign in to comment.