Skip to content

Commit 2ee073b

Browse files
committed
Apply suggestion
1 parent d2ed96b commit 2ee073b

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

core/src/macros/internals.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,7 @@ 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_failed<T, U>(op: &str, left: &T, right: &U) -> !
8-
where
9-
T: fmt::Debug + ?Sized,
10-
U: fmt::Debug + ?Sized,
11-
{
12-
#[track_caller]
13-
fn inner(op: &str, left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! {
14-
panic!(
15-
r#"assertion failed: `(left {} right)`
16-
left: `{:?}`,
17-
right: `{:?}`"#,
18-
op, left, right
19-
)
20-
}
21-
inner(op, &left, &right)
22-
}
23-
24-
#[cold]
25-
#[doc(hidden)]
26-
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
27-
#[track_caller]
28-
pub fn assert_failed_args<T, U>(op: &str, left: &T, right: &U, args: fmt::Arguments<'_>) -> !
7+
pub fn assert_failed<T, U>(op: &str, left: &T, right: &U, args: Option<fmt::Arguments<'_>>) -> !
298
where
309
T: fmt::Debug + ?Sized,
3110
U: fmt::Debug + ?Sized,
@@ -35,14 +14,22 @@ where
3514
op: &str,
3615
left: &dyn fmt::Debug,
3716
right: &dyn fmt::Debug,
38-
args: fmt::Arguments<'_>,
17+
args: Option<fmt::Arguments<'_>>,
3918
) -> ! {
40-
panic!(
41-
r#"assertion failed: `(left {} right)`
19+
match args {
20+
Some(args) => panic!(
21+
r#"assertion failed: `(left {} right)`
4222
left: `{:?}`,
4323
right: `{:?}: {}`"#,
44-
op, left, right, args
45-
)
24+
op, left, right, args
25+
),
26+
None => panic!(
27+
r#"assertion failed: `(left {} right)`
28+
left: `{:?}`,
29+
right: `{:?}`"#,
30+
op, left, right,
31+
),
32+
}
4633
}
4734
inner(op, &left, &right, args)
4835
}

core/src/macros/mod.rs

Lines changed: 4 additions & 4 deletions
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_failed("==", &*left_val, &*right_val);
69+
$crate::macros_internals::assert_failed("==", &*left_val, &*right_val, $crate::option::Option::None);
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_failed_args("==", &*left_val, &*right_val, $crate::format_args!($($arg)+));
81+
$crate::macros_internals::assert_failed("==", &*left_val, &*right_val, $crate::option::Option::Some($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_failed("!=", &*left_val, &*right_val);
116+
$crate::macros_internals::assert_failed("!=", &*left_val, &*right_val, $crate::option::Option::None);
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_failed_args("!=", &*left_val, &*right_val, $crate::format_args!($($arg)+));
128+
$crate::macros_internals::assert_failed("!=", &*left_val, &*right_val, $crate::option::Option::Some($crate::format_args!($($arg)+)));
129129
}
130130
}
131131
}

0 commit comments

Comments
 (0)