Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 authored and gitbot committed Feb 20, 2025
1 parent 29017b4 commit f059e7f
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 250 deletions.
16 changes: 10 additions & 6 deletions alloc/src/collections/btree/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ fn test_difference() {
check_difference(&[1, 3, 5, 9, 11], &[3, 6, 9], &[1, 5, 11]);
check_difference(&[1, 3, 5, 9, 11], &[0, 1], &[3, 5, 9, 11]);
check_difference(&[1, 3, 5, 9, 11], &[11, 12], &[1, 3, 5, 9]);
check_difference(&[-5, 11, 22, 33, 40, 42], &[-12, -5, 14, 23, 34, 38, 39, 50], &[
11, 22, 33, 40, 42,
]);
check_difference(
&[-5, 11, 22, 33, 40, 42],
&[-12, -5, 14, 23, 34, 38, 39, 50],
&[11, 22, 33, 40, 42],
);

if cfg!(miri) {
// Miri is too slow
Expand Down Expand Up @@ -250,9 +252,11 @@ fn test_union() {
check_union(&[], &[], &[]);
check_union(&[1, 2, 3], &[2], &[1, 2, 3]);
check_union(&[2], &[1, 2, 3], &[1, 2, 3]);
check_union(&[1, 3, 5, 9, 11, 16, 19, 24], &[-2, 1, 5, 9, 13, 19], &[
-2, 1, 3, 5, 9, 11, 13, 16, 19, 24,
]);
check_union(
&[1, 3, 5, 9, 11, 16, 19, 24],
&[-2, 1, 5, 9, 13, 19],
&[-2, 1, 3, 5, 9, 11, 13, 16, 19, 24],
);
}

#[test]
Expand Down
28 changes: 16 additions & 12 deletions alloc/src/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,10 @@ fn test_cursor_mut_insert() {
cursor.splice_after(p);
cursor.splice_before(q);
check_links(&m);
assert_eq!(m.iter().cloned().collect::<Vec<_>>(), &[
200, 201, 202, 203, 1, 100, 101, 102, 103, 8, 2, 3, 4, 5, 6
]);
assert_eq!(
m.iter().cloned().collect::<Vec<_>>(),
&[200, 201, 202, 203, 1, 100, 101, 102, 103, 8, 2, 3, 4, 5, 6]
);
let mut cursor = m.cursor_front_mut();
cursor.move_prev();
let tmp = cursor.split_before();
Expand Down Expand Up @@ -915,9 +916,10 @@ fn extract_if_complex() {
assert_eq!(removed, vec![2, 4, 6, 18, 20, 22, 24, 26, 34, 36]);

assert_eq!(list.len(), 14);
assert_eq!(list.into_iter().collect::<Vec<_>>(), vec![
1, 7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39
]);
assert_eq!(
list.into_iter().collect::<Vec<_>>(),
vec![1, 7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39]
);
}

{
Expand All @@ -932,9 +934,10 @@ fn extract_if_complex() {
assert_eq!(removed, vec![2, 4, 6, 18, 20, 22, 24, 26, 34, 36]);

assert_eq!(list.len(), 13);
assert_eq!(list.into_iter().collect::<Vec<_>>(), vec![
7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39
]);
assert_eq!(
list.into_iter().collect::<Vec<_>>(),
vec![7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39]
);
}

{
Expand All @@ -949,9 +952,10 @@ fn extract_if_complex() {
assert_eq!(removed, vec![2, 4, 6, 18, 20, 22, 24, 26, 34, 36]);

assert_eq!(list.len(), 11);
assert_eq!(list.into_iter().collect::<Vec<_>>(), vec![
7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35
]);
assert_eq!(
list.into_iter().collect::<Vec<_>>(),
vec![7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35]
);
}

{
Expand Down
7 changes: 4 additions & 3 deletions alloc/src/collections/vec_deque/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,10 @@ fn make_contiguous_head_to_end() {
tester.push_front(i as char);
}

assert_eq!(tester, [
'P', 'O', 'N', 'M', 'L', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'
]);
assert_eq!(
tester,
['P', 'O', 'N', 'M', 'L', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
);

// ABCDEFGHIJKPONML
let expected_start = 0;
Expand Down
9 changes: 4 additions & 5 deletions alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2350,11 +2350,10 @@ impl<T: Default> Default for Rc<T> {
fn default() -> Rc<T> {
unsafe {
Self::from_inner(
Box::leak(Box::write(Box::new_uninit(), RcInner {
strong: Cell::new(1),
weak: Cell::new(1),
value: T::default(),
}))
Box::leak(Box::write(
Box::new_uninit(),
RcInner { strong: Cell::new(1), weak: Cell::new(1), value: T::default() },
))
.into(),
)
}
Expand Down
13 changes: 8 additions & 5 deletions alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3466,11 +3466,14 @@ impl<T: Default> Default for Arc<T> {
fn default() -> Arc<T> {
unsafe {
Self::from_inner(
Box::leak(Box::write(Box::new_uninit(), ArcInner {
strong: atomic::AtomicUsize::new(1),
weak: atomic::AtomicUsize::new(1),
data: T::default(),
}))
Box::leak(Box::write(
Box::new_uninit(),
ArcInner {
strong: atomic::AtomicUsize::new(1),
weak: atomic::AtomicUsize::new(1),
data: T::default(),
},
))
.into(),
)
}
Expand Down
165 changes: 88 additions & 77 deletions alloc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,18 +1524,14 @@ fn test_lines() {
t("bare\r", &["bare\r"]);
t("bare\rcr", &["bare\rcr"]);
t("Text\n\r", &["Text", "\r"]);
t("\nMäry häd ä little lämb\n\r\nLittle lämb\n", &[
"",
"Märy häd ä little lämb",
"",
"Little lämb",
]);
t("\r\nMäry häd ä little lämb\n\nLittle lämb", &[
"",
"Märy häd ä little lämb",
"",
"Little lämb",
]);
t(
"\nMäry häd ä little lämb\n\r\nLittle lämb\n",
&["", "Märy häd ä little lämb", "", "Little lämb"],
);
t(
"\r\nMäry häd ä little lämb\n\nLittle lämb",
&["", "Märy häd ä little lämb", "", "Little lämb"],
);
}

#[test]
Expand Down Expand Up @@ -1978,73 +1974,88 @@ mod pattern {
assert_eq!(v, right);
}

make_test!(str_searcher_ascii_haystack, "bb", "abbcbbd", [
Reject(0, 1),
Match(1, 3),
Reject(3, 4),
Match(4, 6),
Reject(6, 7),
]);
make_test!(str_searcher_ascii_haystack_seq, "bb", "abbcbbbbd", [
Reject(0, 1),
Match(1, 3),
Reject(3, 4),
Match(4, 6),
Match(6, 8),
Reject(8, 9),
]);
make_test!(str_searcher_empty_needle_ascii_haystack, "", "abbcbbd", [
Match(0, 0),
Reject(0, 1),
Match(1, 1),
Reject(1, 2),
Match(2, 2),
Reject(2, 3),
Match(3, 3),
Reject(3, 4),
Match(4, 4),
Reject(4, 5),
Match(5, 5),
Reject(5, 6),
Match(6, 6),
Reject(6, 7),
Match(7, 7),
]);
make_test!(str_searcher_multibyte_haystack, " ", "├──", [
Reject(0, 3),
Reject(3, 6),
Reject(6, 9),
]);
make_test!(str_searcher_empty_needle_multibyte_haystack, "", "├──", [
Match(0, 0),
Reject(0, 3),
Match(3, 3),
Reject(3, 6),
Match(6, 6),
Reject(6, 9),
Match(9, 9),
]);
make_test!(
str_searcher_ascii_haystack,
"bb",
"abbcbbd",
[Reject(0, 1), Match(1, 3), Reject(3, 4), Match(4, 6), Reject(6, 7),]
);
make_test!(
str_searcher_ascii_haystack_seq,
"bb",
"abbcbbbbd",
[Reject(0, 1), Match(1, 3), Reject(3, 4), Match(4, 6), Match(6, 8), Reject(8, 9),]
);
make_test!(
str_searcher_empty_needle_ascii_haystack,
"",
"abbcbbd",
[
Match(0, 0),
Reject(0, 1),
Match(1, 1),
Reject(1, 2),
Match(2, 2),
Reject(2, 3),
Match(3, 3),
Reject(3, 4),
Match(4, 4),
Reject(4, 5),
Match(5, 5),
Reject(5, 6),
Match(6, 6),
Reject(6, 7),
Match(7, 7),
]
);
make_test!(
str_searcher_multibyte_haystack,
" ",
"├──",
[Reject(0, 3), Reject(3, 6), Reject(6, 9),]
);
make_test!(
str_searcher_empty_needle_multibyte_haystack,
"",
"├──",
[
Match(0, 0),
Reject(0, 3),
Match(3, 3),
Reject(3, 6),
Match(6, 6),
Reject(6, 9),
Match(9, 9),
]
);
make_test!(str_searcher_empty_needle_empty_haystack, "", "", [Match(0, 0),]);
make_test!(str_searcher_nonempty_needle_empty_haystack, "├", "", []);
make_test!(char_searcher_ascii_haystack, 'b', "abbcbbd", [
Reject(0, 1),
Match(1, 2),
Match(2, 3),
Reject(3, 4),
Match(4, 5),
Match(5, 6),
Reject(6, 7),
]);
make_test!(char_searcher_multibyte_haystack, ' ', "├──", [
Reject(0, 3),
Reject(3, 6),
Reject(6, 9),
]);
make_test!(char_searcher_short_haystack, '\u{1F4A9}', "* \t", [
Reject(0, 1),
Reject(1, 2),
Reject(2, 3),
]);
make_test!(
char_searcher_ascii_haystack,
'b',
"abbcbbd",
[
Reject(0, 1),
Match(1, 2),
Match(2, 3),
Reject(3, 4),
Match(4, 5),
Match(5, 6),
Reject(6, 7),
]
);
make_test!(
char_searcher_multibyte_haystack,
' ',
"├──",
[Reject(0, 3), Reject(3, 6), Reject(6, 9),]
);
make_test!(
char_searcher_short_haystack,
'\u{1F4A9}',
"* \t",
[Reject(0, 1), Reject(1, 2), Reject(2, 3),]
);

// See #85462
#[test]
Expand Down
35 changes: 22 additions & 13 deletions alloc/tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,28 @@ fn test_fromutf8error_into_lossy() {
#[test]
fn test_from_utf16() {
let pairs = [
(String::from("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"), vec![
0xd800, 0xdf45, 0xd800, 0xdf3f, 0xd800, 0xdf3b, 0xd800, 0xdf46, 0xd800, 0xdf39, 0xd800,
0xdf3b, 0xd800, 0xdf30, 0x000a,
]),
(String::from("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"), vec![
0xd801, 0xdc12, 0xd801, 0xdc49, 0xd801, 0xdc2e, 0xd801, 0xdc40, 0xd801, 0xdc32, 0xd801,
0xdc4b, 0x0020, 0xd801, 0xdc0f, 0xd801, 0xdc32, 0xd801, 0xdc4d, 0x000a,
]),
(String::from("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"), vec![
0xd800, 0xdf00, 0xd800, 0xdf16, 0xd800, 0xdf0b, 0xd800, 0xdf04, 0xd800, 0xdf11, 0xd800,
0xdf09, 0x00b7, 0xd800, 0xdf0c, 0xd800, 0xdf04, 0xd800, 0xdf15, 0xd800, 0xdf04, 0xd800,
0xdf0b, 0xd800, 0xdf09, 0xd800, 0xdf11, 0x000a,
]),
(
String::from("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
vec![
0xd800, 0xdf45, 0xd800, 0xdf3f, 0xd800, 0xdf3b, 0xd800, 0xdf46, 0xd800, 0xdf39,
0xd800, 0xdf3b, 0xd800, 0xdf30, 0x000a,
],
),
(
String::from("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
vec![
0xd801, 0xdc12, 0xd801, 0xdc49, 0xd801, 0xdc2e, 0xd801, 0xdc40, 0xd801, 0xdc32,
0xd801, 0xdc4b, 0x0020, 0xd801, 0xdc0f, 0xd801, 0xdc32, 0xd801, 0xdc4d, 0x000a,
],
),
(
String::from("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
vec![
0xd800, 0xdf00, 0xd800, 0xdf16, 0xd800, 0xdf0b, 0xd800, 0xdf04, 0xd800, 0xdf11,
0xd800, 0xdf09, 0x00b7, 0xd800, 0xdf0c, 0xd800, 0xdf04, 0xd800, 0xdf15, 0xd800,
0xdf04, 0xd800, 0xdf0b, 0xd800, 0xdf09, 0xd800, 0xdf11, 0x000a,
],
),
(
String::from("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
vec![
Expand Down
17 changes: 8 additions & 9 deletions core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,10 +1590,10 @@ impl<'b, T: ?Sized> Ref<'b, T> {
{
let (a, b) = f(&*orig);
let borrow = orig.borrow.clone();
(Ref { value: NonNull::from(a), borrow }, Ref {
value: NonNull::from(b),
borrow: orig.borrow,
})
(
Ref { value: NonNull::from(a), borrow },
Ref { value: NonNull::from(b), borrow: orig.borrow },
)
}

/// Converts into a reference to the underlying data.
Expand Down Expand Up @@ -1758,11 +1758,10 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
{
let borrow = orig.borrow.clone();
let (a, b) = f(&mut *orig);
(RefMut { value: NonNull::from(a), borrow, marker: PhantomData }, RefMut {
value: NonNull::from(b),
borrow: orig.borrow,
marker: PhantomData,
})
(
RefMut { value: NonNull::from(a), borrow, marker: PhantomData },
RefMut { value: NonNull::from(b), borrow: orig.borrow, marker: PhantomData },
)
}

/// Converts into a mutable reference to the underlying data.
Expand Down
Loading

0 comments on commit f059e7f

Please sign in to comment.