Skip to content

Commit 52197d3

Browse files
committed
Fix UI tests and merge assert_eq and assert_ne internal functions
1 parent bbad2b2 commit 52197d3

12 files changed

+151
-725
lines changed

library/core/src/macros/internals.rs

+19-56
Original file line numberDiff line numberDiff line change
@@ -4,82 +4,45 @@ use crate::{fmt, panic};
44
#[doc(hidden)]
55
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
66
#[track_caller]
7-
pub fn assert_eq_failed<T, U>(left: &T, right: &U) -> !
7+
pub fn assert_failed<T, U>(op: &str, left: &T, right: &U) -> !
88
where
99
T: fmt::Debug + ?Sized,
1010
U: fmt::Debug + ?Sized,
1111
{
1212
#[track_caller]
13-
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! {
13+
fn inner(op: &str, left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! {
1414
panic!(
15-
r#"assertion failed: `(left == right)`
16-
left: `{:?}`,
17-
right: `{:?}`"#,
18-
left, right
15+
r#"assertion failed: `(left {} right)`
16+
left: `{:?}`,
17+
right: `{:?}`"#,
18+
op, left, right
1919
)
2020
}
21-
inner(&left, &right)
21+
inner(op, &left, &right)
2222
}
2323

2424
#[cold]
2525
#[doc(hidden)]
2626
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
2727
#[track_caller]
28-
pub fn assert_eq_failed_args<T, U>(left: &T, right: &U, args: fmt::Arguments<'_>) -> !
28+
pub fn assert_failed_args<T, U>(op: &str, left: &T, right: &U, args: fmt::Arguments<'_>) -> !
2929
where
3030
T: fmt::Debug + ?Sized,
3131
U: fmt::Debug + ?Sized,
3232
{
3333
#[track_caller]
34-
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug, args: fmt::Arguments<'_>) -> ! {
34+
fn inner(
35+
op: &str,
36+
left: &dyn fmt::Debug,
37+
right: &dyn fmt::Debug,
38+
args: fmt::Arguments<'_>,
39+
) -> ! {
3540
panic!(
36-
r#"assertion failed: `(left == right)`
37-
left: `{:?}`,
38-
right: `{:?}: {}`"#,
39-
left, right, args
41+
r#"assertion failed: `(left {} right)`
42+
left: `{:?}`,
43+
right: `{:?}: {}`"#,
44+
op, left, right, args
4045
)
4146
}
42-
inner(&left, &right, args)
43-
}
44-
45-
#[cold]
46-
#[doc(hidden)]
47-
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
48-
#[track_caller]
49-
pub fn assert_ne_failed<T, U>(left: &T, right: &U) -> !
50-
where
51-
T: fmt::Debug + ?Sized,
52-
U: fmt::Debug + ?Sized,
53-
{
54-
#[track_caller]
55-
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! {
56-
panic!(
57-
r#"assertion failed: `(left != right)`
58-
left: `{:?}`,
59-
right: `{:?}`"#,
60-
left, right
61-
)
62-
}
63-
inner(&left, &right)
64-
}
65-
66-
#[cold]
67-
#[doc(hidden)]
68-
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
69-
#[track_caller]
70-
pub fn assert_ne_failed_args<T, U>(left: &T, right: &U, args: fmt::Arguments<'_>) -> !
71-
where
72-
T: fmt::Debug + ?Sized,
73-
U: fmt::Debug + ?Sized,
74-
{
75-
#[track_caller]
76-
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug, args: fmt::Arguments<'_>) -> ! {
77-
panic!(
78-
r#"assertion failed: `(left != right)`
79-
left: `{:?}`,
80-
right: `{:?}: {}`"#,
81-
left, right, args
82-
)
83-
}
84-
inner(&left, &right, args)
47+
inner(op, &left, &right, args)
8548
}

library/core/src/macros/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ macro_rules! assert_eq {
6666
// The reborrows below are intentional. Without them, the stack slot for the
6767
// borrow is initialized even before the values are compared, leading to a
6868
// noticeable slow down.
69-
$crate::macros_internals::assert_eq_failed(&*left_val, &*right_val);
69+
$crate::macros_internals::assert_failed("==", &*left_val, &*right_val);
7070
}
7171
}
7272
}
@@ -78,7 +78,7 @@ macro_rules! assert_eq {
7878
// The reborrows below are intentional. Without them, the stack slot for the
7979
// borrow is initialized even before the values are compared, leading to a
8080
// noticeable slow down.
81-
$crate::macros_internals::assert_eq_failed_args(&*left_val, &*right_val, $crate::format_args!($($arg)+));
81+
$crate::macros_internals::assert_failed_args("==", &*left_val, &*right_val, $crate::format_args!($($arg)+));
8282
}
8383
}
8484
}
@@ -113,7 +113,7 @@ macro_rules! assert_ne {
113113
// The reborrows below are intentional. Without them, the stack slot for the
114114
// borrow is initialized even before the values are compared, leading to a
115115
// noticeable slow down.
116-
$crate::macros_internals::assert_eq_failed(&*left_val, &*right_val);
116+
$crate::macros_internals::assert_failed("!=", &*left_val, &*right_val);
117117
}
118118
}
119119
}
@@ -125,7 +125,7 @@ macro_rules! assert_ne {
125125
// The reborrows below are intentional. Without them, the stack slot for the
126126
// borrow is initialized even before the values are compared, leading to a
127127
// noticeable slow down.
128-
$crate::macros_internals::assert_ne_failed_args(&*left_val, &*right_val, $crate::format_args!($($arg)+));
128+
$crate::macros_internals::assert_failed_args("!=", &*left_val, &*right_val, $crate::format_args!($($arg)+));
129129
}
130130
}
131131
}

0 commit comments

Comments
 (0)