From eac1d63ea3cb6c4af1b192d9716966b79d8626d1 Mon Sep 17 00:00:00 2001 From: tuguzT Date: Fri, 29 Aug 2025 15:03:25 +0300 Subject: [PATCH 1/2] Trying to generalize tuple `PartialEq` & `PartialOrd` impls --- library/core/src/tuple.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 23a0a6877df77..7488df6f9181b 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -23,13 +23,13 @@ macro_rules! tuple_impls { maybe_tuple_doc! { $($T)+ @ #[stable(feature = "rust1", since = "1.0.0")] - impl<$($T: PartialEq),+> PartialEq for ($($T,)+) { + impl<$(${concat($T, _)}, $T: PartialEq<${concat($T, _)}>),+> PartialEq<($(${concat($T, _)},)+)> for ($($T,)+) { #[inline] - fn eq(&self, other: &($($T,)+)) -> bool { + fn eq(&self, other: &($(${concat($T, _)},)+)) -> bool { $( ${ignore($T)} self.${index()} == other.${index()} )&&+ } #[inline] - fn ne(&self, other: &($($T,)+)) -> bool { + fn ne(&self, other: &($(${concat($T, _)},)+)) -> bool { $( ${ignore($T)} self.${index()} != other.${index()} )||+ } } @@ -66,42 +66,42 @@ macro_rules! tuple_impls { maybe_tuple_doc! { $($T)+ @ #[stable(feature = "rust1", since = "1.0.0")] - impl<$($T: PartialOrd),+> PartialOrd for ($($T,)+) + impl<$(${concat($T, _)}, $T: PartialOrd<${concat($T, _)}>),+> PartialOrd<($(${concat($T, _)},)+)> for ($($T,)+) { #[inline] - fn partial_cmp(&self, other: &($($T,)+)) -> Option { + fn partial_cmp(&self, other: &($(${concat($T, _)},)+)) -> Option { lexical_partial_cmp!($( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn lt(&self, other: &($($T,)+)) -> bool { + fn lt(&self, other: &($(${concat($T, _)},)+)) -> bool { lexical_ord!(lt, __chaining_lt, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn le(&self, other: &($($T,)+)) -> bool { + fn le(&self, other: &($(${concat($T, _)},)+)) -> bool { lexical_ord!(le, __chaining_le, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn ge(&self, other: &($($T,)+)) -> bool { + fn ge(&self, other: &($(${concat($T, _)},)+)) -> bool { lexical_ord!(ge, __chaining_ge, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn gt(&self, other: &($($T,)+)) -> bool { + fn gt(&self, other: &($(${concat($T, _)},)+)) -> bool { lexical_ord!(gt, __chaining_gt, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn __chaining_lt(&self, other: &($($T,)+)) -> ControlFlow { + fn __chaining_lt(&self, other: &($(${concat($T, _)},)+)) -> ControlFlow { lexical_chain!(__chaining_lt, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn __chaining_le(&self, other: &($($T,)+)) -> ControlFlow { + fn __chaining_le(&self, other: &($(${concat($T, _)},)+)) -> ControlFlow { lexical_chain!(__chaining_le, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn __chaining_gt(&self, other: &($($T,)+)) -> ControlFlow { + fn __chaining_gt(&self, other: &($(${concat($T, _)},)+)) -> ControlFlow { lexical_chain!(__chaining_gt, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } #[inline] - fn __chaining_ge(&self, other: &($($T,)+)) -> ControlFlow { + fn __chaining_ge(&self, other: &($(${concat($T, _)},)+)) -> ControlFlow { lexical_chain!(__chaining_ge, $( ${ignore($T)} self.${index()}, other.${index()} ),+) } } From 473c390fdd57f741d9a0382bb99f61d58e812f11 Mon Sep 17 00:00:00 2001 From: tuguzT Date: Fri, 29 Aug 2025 17:46:07 +0300 Subject: [PATCH 2/2] Update tests involving slice & string comparisons --- .../src/binary_search_util/tests.rs | 4 +-- compiler/rustc_interface/src/tests.rs | 2 +- .../alloc/src/collections/vec_deque/tests.rs | 30 +++++++------------ library/alloctests/tests/vec.rs | 8 ++--- library/coretests/tests/num/flt2dec/mod.rs | 4 +-- .../src/sys/net/connection/socket/tests.rs | 4 +-- .../crates/test-utils/src/lib.rs | 4 +-- 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_data_structures/src/binary_search_util/tests.rs b/compiler/rustc_data_structures/src/binary_search_util/tests.rs index d74febb5c0fc4..2dd0b6d588511 100644 --- a/compiler/rustc_data_structures/src/binary_search_util/tests.rs +++ b/compiler/rustc_data_structures/src/binary_search_util/tests.rs @@ -16,8 +16,8 @@ fn get_key(data: &Element) -> usize { fn binary_search_slice_test() { let map = test_map(); assert_eq!(binary_search_slice(&map, get_key, &0), &[(0, "zero")]); - assert_eq!(binary_search_slice(&map, get_key, &1), &[]); + assert_eq!(binary_search_slice(&map, get_key, &1), &map[..0]); assert_eq!(binary_search_slice(&map, get_key, &3), &[(3, "three-a"), (3, "three-b")]); assert_eq!(binary_search_slice(&map, get_key, &22), &[(22, "twenty-two")]); - assert_eq!(binary_search_slice(&map, get_key, &23), &[]); + assert_eq!(binary_search_slice(&map, get_key, &23), &map[..0]); } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 7730bddc0f12d..87936aa4131f4 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -670,7 +670,7 @@ fn test_top_level_options_tracked_no_crate() { real_rust_source_base_dir, Some("/home/bors/rust/.rustup/toolchains/nightly/lib/rustlib/src/rust".into()) ); - tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]); + tracked!(remap_path_prefix, vec![(PathBuf::from("/home/bors/rust"), PathBuf::from("src"))]); // tidy-alphabetical-end } diff --git a/library/alloc/src/collections/vec_deque/tests.rs b/library/alloc/src/collections/vec_deque/tests.rs index ad76cb14deb86..d7a6e9c9d4521 100644 --- a/library/alloc/src/collections/vec_deque/tests.rs +++ b/library/alloc/src/collections/vec_deque/tests.rs @@ -479,12 +479,12 @@ fn make_contiguous_big_head() { // 012......9876543 assert_eq!(tester.capacity(), 15); - assert_eq!((&[9, 8, 7, 6, 5, 4, 3] as &[_], &[0, 1, 2] as &[_]), tester.as_slices()); + assert_eq!(tester.as_slices(), ([9, 8, 7, 6, 5, 4, 3], [0, 1, 2])); let expected_start = tester.as_slices().1.len(); tester.make_contiguous(); assert_eq!(tester.head, expected_start); - assert_eq!((&[9, 8, 7, 6, 5, 4, 3, 0, 1, 2] as &[_], &[] as &[_]), tester.as_slices()); + assert_eq!(tester.as_slices(), ([9, 8, 7, 6, 5, 4, 3, 0, 1, 2], [])); } #[test] @@ -503,7 +503,7 @@ fn make_contiguous_big_tail() { let expected_start = 0; tester.make_contiguous(); assert_eq!(tester.head, expected_start); - assert_eq!((&[9, 8, 0, 1, 2, 3, 4, 5, 6, 7] as &[_], &[] as &[_]), tester.as_slices()); + assert_eq!(tester.as_slices(), ([9, 8, 0, 1, 2, 3, 4, 5, 6, 7], [])); } #[test] @@ -525,8 +525,8 @@ fn make_contiguous_small_free() { tester.make_contiguous(); assert_eq!(tester.head, expected_start); assert_eq!( - (&['M', 'L', 'K', 'J', 'I', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] as &[_], &[] as &[_]), - tester.as_slices() + tester.as_slices(), + (['M', 'L', 'K', 'J', 'I', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], []) ); tester.clear(); @@ -543,8 +543,8 @@ fn make_contiguous_small_free() { tester.make_contiguous(); assert_eq!(tester.head, expected_start); assert_eq!( - (&['H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', 'I', 'J', 'K', 'L', 'M'] as &[_], &[] as &[_]), - tester.as_slices() + tester.as_slices(), + (['H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', 'I', 'J', 'K', 'L', 'M'], []) ); } @@ -570,12 +570,8 @@ fn make_contiguous_head_to_end() { tester.make_contiguous(); assert_eq!(tester.head, expected_start); assert_eq!( - ( - &['P', 'O', 'N', 'M', 'L', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'] - as &[_], - &[] as &[_] - ), - tester.as_slices() + tester.as_slices(), + (['P', 'O', 'N', 'M', 'L', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'], []) ); tester.clear(); @@ -592,12 +588,8 @@ fn make_contiguous_head_to_end() { tester.make_contiguous(); assert_eq!(tester.head, expected_start); assert_eq!( - ( - &['K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', 'L', 'M', 'N', 'O', 'P'] - as &[_], - &[] as &[_] - ), - tester.as_slices() + tester.as_slices(), + (['K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', 'L', 'M', 'N', 'O', 'P'], []) ); } diff --git a/library/alloctests/tests/vec.rs b/library/alloctests/tests/vec.rs index 00f640cd17ea4..2efe1b49d1ae5 100644 --- a/library/alloctests/tests/vec.rs +++ b/library/alloctests/tests/vec.rs @@ -505,10 +505,10 @@ fn zero_sized_values() { #[test] fn test_partition() { - assert_eq!([].into_iter().partition(|x: &i32| *x < 3), (vec![], vec![])); - assert_eq!([1, 2, 3].into_iter().partition(|x| *x < 4), (vec![1, 2, 3], vec![])); - assert_eq!([1, 2, 3].into_iter().partition(|x| *x < 2), (vec![1], vec![2, 3])); - assert_eq!([1, 2, 3].into_iter().partition(|x| *x < 0), (vec![], vec![1, 2, 3])); + assert_eq!([].into_iter().partition::, _>(|x: &i32| *x < 3), ([], [])); + assert_eq!([1, 2, 3].into_iter().partition::, _>(|x| *x < 4), ([1, 2, 3], [])); + assert_eq!([1, 2, 3].into_iter().partition::, _>(|x| *x < 2), ([1], [2, 3])); + assert_eq!([1, 2, 3].into_iter().partition::, _>(|x| *x < 0), ([], [1, 2, 3])); } #[test] diff --git a/library/coretests/tests/num/flt2dec/mod.rs b/library/coretests/tests/num/flt2dec/mod.rs index 4e73bd1f12ee9..3c59c799a39e0 100644 --- a/library/coretests/tests/num/flt2dec/mod.rs +++ b/library/coretests/tests/num/flt2dec/mod.rs @@ -194,10 +194,10 @@ where let v: T = TestableFloat::ldexpi(x, e); let decoded = decode_finite(v); - try_exact!(f(&decoded) => &mut buf, &expected, expectedk; + try_exact!(f(&decoded) => &mut buf, expected, expectedk; "exact mismatch for v={x}p{e}{t}: actual {actual:?}, expected {expected:?}", x = x, e = e, t = tstr); - try_fixed!(f(&decoded) => &mut buf, expectedk - expected.len() as i16, &expected, expectedk; + try_fixed!(f(&decoded) => &mut buf, expectedk - expected.len() as i16, expected, expectedk; "fixed mismatch for v={x}p{e}{t}: actual {actual:?}, expected {expected:?}", x = x, e = e, t = tstr); } diff --git a/library/std/src/sys/net/connection/socket/tests.rs b/library/std/src/sys/net/connection/socket/tests.rs index fc236b8027b67..e55ea442b29c9 100644 --- a/library/std/src/sys/net/connection/socket/tests.rs +++ b/library/std/src/sys/net/connection/socket/tests.rs @@ -12,8 +12,8 @@ fn no_lookup_host_duplicates() { *addrs.entry(sa).or_insert(0) += 1; } assert_eq!( - addrs.iter().filter(|&(_, &v)| v > 1).collect::>(), - vec![], + addrs.into_iter().filter(|&(_, v)| v > 1).collect::>(), + [], "There should be no duplicate localhost entries" ); } diff --git a/src/tools/rust-analyzer/crates/test-utils/src/lib.rs b/src/tools/rust-analyzer/crates/test-utils/src/lib.rs index d3afac85017f7..8282a01bdc131 100644 --- a/src/tools/rust-analyzer/crates/test-utils/src/lib.rs +++ b/src/tools/rust-analyzer/crates/test-utils/src/lib.rs @@ -363,7 +363,7 @@ fn main() { assert_eq!( res[..3], - [("x", "def".into()), ("y", "def".into()), ("zoo", "type:\ni32\n".into())] + [("x", "def".to_owned()), ("y", "def".to_owned()), ("zoo", "type:\ni32\n".to_owned())] ); assert_eq!(res[3].0.len(), 115); } @@ -384,7 +384,7 @@ fn main() { .map(|(range, ann)| (&text[range], ann)) .collect::>(); - assert_eq!(res, [("x", "a".into()), ("y", "b".into()), ("(x, y)", "c".into())]); + assert_eq!(res, [("x", "a".to_owned()), ("y", "b".to_owned()), ("(x, y)", "c".to_owned())]); } /// Returns `false` if slow tests should not run, otherwise returns `true` and