Skip to content

Commit f138e26

Browse files
committed
Apply suggestion
1 parent 52197d3 commit f138e26

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

library/core/src/macros/internals.rs

+14-27
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
}

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_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
}

src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
let mut _10: &str; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1515
let mut _11: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1616
let mut _12: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
17+
let mut _13: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1718
scope 1 {
1819
debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14
1920
let _4: std::option::Option<i32>; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14
@@ -71,10 +72,12 @@
7172
// mir::Constant
7273
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
7374
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [61, 61], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [3], len: Size { raw: 2 } }, size: Size { raw: 2 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 2 }) }
74-
core::macros::internals::assert_failed::<i32, i32>(move _10, move _11, move _12); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
75+
StorageLive(_13); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
76+
discriminant(_13) = 0; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
77+
core::macros::internals::assert_failed::<i32, i32>(move _10, move _11, move _12, move _13); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
7578
// mir::Constant
7679
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
77-
// + literal: Const { ty: for<'r, 's, 't0> fn(&'r str, &'s i32, &'t0 i32) -> ! {core::macros::internals::assert_failed::<i32, i32>}, val: Value(Scalar(<ZST>)) }
80+
// + literal: Const { ty: for<'r, 's, 't0, 't1> fn(&'r str, &'s i32, &'t0 i32, std::option::Option<std::fmt::Arguments<'t1>>) -> ! {core::macros::internals::assert_failed::<i32, i32>}, val: Value(Scalar(<ZST>)) }
7881
}
7982

8083
bb2: {

src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
let _24: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2727
let mut _25: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2828
let _26: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
29+
let mut _27: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2930
scope 1 {
3031
debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14
3132
let _6: std::option::Option<i32>; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14
3233
scope 3 {
3334
debug _prev => _6; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14
3435
let _13: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3536
let _14: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
36-
let mut _27: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
37+
let mut _28: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3738
scope 4 {
3839
debug left_val => _13; // in scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3940
debug right_val => _14; // in scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -77,14 +78,14 @@
7778
StorageLive(_10); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
7879
_10 = &_1; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
7980
StorageLive(_11); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
80-
_27 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
81+
_28 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
8182
// ty::Const
8283
// + ty: &i32
8384
// + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, [], Some(promoted[0]))
8485
// mir::Constant
8586
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
8687
// + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, [], Some(promoted[0])) }
87-
_11 = _27; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
88+
_11 = _28; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
8889
(_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
8990
(_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
9091
StorageDead(_11); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -127,10 +128,12 @@
127128
StorageLive(_26); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
128129
_26 = _14; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
129130
_25 = _26; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
130-
core::macros::internals::assert_failed::<i32, i32>(move _21, move _23, move _25); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
131+
StorageLive(_27); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
132+
discriminant(_27) = 0; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
133+
core::macros::internals::assert_failed::<i32, i32>(move _21, move _23, move _25, move _27); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
131134
// mir::Constant
132135
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
133-
// + literal: Const { ty: for<'r, 's, 't0> fn(&'r str, &'s i32, &'t0 i32) -> ! {core::macros::internals::assert_failed::<i32, i32>}, val: Value(Scalar(<ZST>)) }
136+
// + literal: Const { ty: for<'r, 's, 't0, 't1> fn(&'r str, &'s i32, &'t0 i32, std::option::Option<std::fmt::Arguments<'t1>>) -> ! {core::macros::internals::assert_failed::<i32, i32>}, val: Value(Scalar(<ZST>)) }
134137
}
135138

136139
bb4: {

src/test/ui/hygiene/no_implicit_prelude.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ LL | ().clone()
2929

3030
error: aborting due to 2 previous errors
3131

32-
Some errors have detailed explanations: E0282, E0433, E0599.
33-
For more information about an error, try `rustc --explain E0282`.
32+
Some errors have detailed explanations: E0433, E0599.
33+
For more information about an error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)