Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Const Compare for Tuples #104125

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions library/core/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ macro_rules! tuple_impls {
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialEq),+> PartialEq for ($($T,)+)
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
impl<$($T: ~const PartialEq),+> const PartialEq for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{
Expand All @@ -40,7 +41,7 @@ macro_rules! tuple_impls {
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Eq),+> Eq for ($($T,)+)
impl<$($T: Eq),+> Eq for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{}
Expand All @@ -49,7 +50,8 @@ macro_rules! tuple_impls {
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+)
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
impl<$($T: ~const PartialOrd + ~const PartialEq),+> const PartialOrd for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{
Expand Down Expand Up @@ -79,7 +81,8 @@ macro_rules! tuple_impls {
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Ord),+> Ord for ($($T,)+)
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
impl<$($T: ~const Ord),+> const Ord for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{
Expand Down
19 changes: 8 additions & 11 deletions src/test/ui/consts/fn_trait_refs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// build-pass
// check-pass

#![feature(const_fn_trait_ref_impls)]
#![feature(fn_traits)]
Expand Down Expand Up @@ -60,21 +60,18 @@ const fn test(i: i32) -> i32 {
i + 1
}

const fn main() {
fn main() {
const fn one() -> i32 {
1
};
const fn two() -> i32 {
2
};
const _: () = {
let test_one = test_fn(one);
assert!(test_one == (1, 1, 1));

// FIXME(const_cmp_tuple)
let test_one = test_fn(one);
assert!(test_one.0 == 1);
assert!(test_one.1 == 1);
assert!(test_one.2 == 1);

let test_two = test_fn_mut(two);
assert!(test_two.0 == 1);
assert!(test_two.1 == 1);
let test_two = test_fn_mut(two);
assert!(test_two == (2, 2));
};
}