From f138e260a00ac16e8532aa406f6738c92e5d27ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Wed, 9 Dec 2020 11:29:42 +0100 Subject: [PATCH] Apply suggestion --- library/core/src/macros/internals.rs | 41 +++++++------------ library/core/src/macros/mod.rs | 8 ++-- .../issue_73223.main.PreCodegen.32bit.diff | 7 +++- ..._73223.main.SimplifyArmIdentity.32bit.diff | 13 +++--- .../ui/hygiene/no_implicit_prelude.stderr | 4 +- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/library/core/src/macros/internals.rs b/library/core/src/macros/internals.rs index 35a28a2e0af..c3ad7398aa1 100644 --- a/library/core/src/macros/internals.rs +++ b/library/core/src/macros/internals.rs @@ -4,28 +4,7 @@ #[doc(hidden)] #[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")] #[track_caller] -pub fn assert_failed(op: &str, left: &T, right: &U) -> ! -where - T: fmt::Debug + ?Sized, - U: fmt::Debug + ?Sized, -{ - #[track_caller] - fn inner(op: &str, left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! { - panic!( - r#"assertion failed: `(left {} right)` - left: `{:?}`, - right: `{:?}`"#, - op, left, right - ) - } - inner(op, &left, &right) -} - -#[cold] -#[doc(hidden)] -#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")] -#[track_caller] -pub fn assert_failed_args(op: &str, left: &T, right: &U, args: fmt::Arguments<'_>) -> ! +pub fn assert_failed(op: &str, left: &T, right: &U, args: Option>) -> ! where T: fmt::Debug + ?Sized, U: fmt::Debug + ?Sized, @@ -35,14 +14,22 @@ fn inner( op: &str, left: &dyn fmt::Debug, right: &dyn fmt::Debug, - args: fmt::Arguments<'_>, + args: Option>, ) -> ! { - panic!( - r#"assertion failed: `(left {} right)` + match args { + Some(args) => panic!( + r#"assertion failed: `(left {} right)` left: `{:?}`, right: `{:?}: {}`"#, - op, left, right, args - ) + op, left, right, args + ), + None => panic!( + r#"assertion failed: `(left {} right)` + left: `{:?}`, + right: `{:?}`"#, + op, left, right, + ), + } } inner(op, &left, &right, args) } diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 30bdae1efa7..f505b7021ed 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -66,7 +66,7 @@ macro_rules! assert_eq { // The reborrows below are intentional. Without them, the stack slot for the // borrow is initialized even before the values are compared, leading to a // noticeable slow down. - $crate::macros_internals::assert_failed("==", &*left_val, &*right_val); + $crate::macros_internals::assert_failed("==", &*left_val, &*right_val, $crate::option::Option::None); } } } @@ -78,7 +78,7 @@ macro_rules! assert_eq { // The reborrows below are intentional. Without them, the stack slot for the // borrow is initialized even before the values are compared, leading to a // noticeable slow down. - $crate::macros_internals::assert_failed_args("==", &*left_val, &*right_val, $crate::format_args!($($arg)+)); + $crate::macros_internals::assert_failed("==", &*left_val, &*right_val, $crate::option::Option::Some($crate::format_args!($($arg)+))); } } } @@ -113,7 +113,7 @@ macro_rules! assert_ne { // The reborrows below are intentional. Without them, the stack slot for the // borrow is initialized even before the values are compared, leading to a // noticeable slow down. - $crate::macros_internals::assert_failed("!=", &*left_val, &*right_val); + $crate::macros_internals::assert_failed("!=", &*left_val, &*right_val, $crate::option::Option::None); } } } @@ -125,7 +125,7 @@ macro_rules! assert_ne { // The reborrows below are intentional. Without them, the stack slot for the // borrow is initialized even before the values are compared, leading to a // noticeable slow down. - $crate::macros_internals::assert_failed_args("!=", &*left_val, &*right_val, $crate::format_args!($($arg)+)); + $crate::macros_internals::assert_failed("!=", &*left_val, &*right_val, $crate::option::Option::Some($crate::format_args!($($arg)+))); } } } diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff index 64b559f6432..46404f5e33c 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff @@ -14,6 +14,7 @@ let mut _10: &str; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL let mut _11: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL let mut _12: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + let mut _13: std::option::Option; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL scope 1 { debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 let _4: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 @@ -71,10 +72,12 @@ // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL // + 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 }) } - core::macros::internals::assert_failed::(move _10, move _11, move _12); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + StorageLive(_13); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + discriminant(_13) = 0; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + core::macros::internals::assert_failed::(move _10, move _11, move _12, move _13); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL - // + literal: Const { ty: for<'r, 's, 't0> fn(&'r str, &'s i32, &'t0 i32) -> ! {core::macros::internals::assert_failed::}, val: Value(Scalar()) } + // + literal: Const { ty: for<'r, 's, 't0, 't1> fn(&'r str, &'s i32, &'t0 i32, std::option::Option>) -> ! {core::macros::internals::assert_failed::}, val: Value(Scalar()) } } bb2: { diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff index 3d19385c343..cf1db80bcfc 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff @@ -26,6 +26,7 @@ let _24: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL let mut _25: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL let _26: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + let mut _27: std::option::Option; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL scope 1 { debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 let _6: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 @@ -33,7 +34,7 @@ debug _prev => _6; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 let _13: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL let _14: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - let mut _27: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + let mut _28: &i32; // in scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL scope 4 { debug left_val => _13; // in scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL debug right_val => _14; // in scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL @@ -77,14 +78,14 @@ StorageLive(_10); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _10 = &_1; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_11); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - _27 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + _28 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, [], Some(promoted[0])) } - _11 = _27; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + _11 = _28; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_11); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL @@ -127,10 +128,12 @@ StorageLive(_26); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _26 = _14; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _25 = _26; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - core::macros::internals::assert_failed::(move _21, move _23, move _25); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + StorageLive(_27); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + discriminant(_27) = 0; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + core::macros::internals::assert_failed::(move _21, move _23, move _25, move _27); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL - // + literal: Const { ty: for<'r, 's, 't0> fn(&'r str, &'s i32, &'t0 i32) -> ! {core::macros::internals::assert_failed::}, val: Value(Scalar()) } + // + literal: Const { ty: for<'r, 's, 't0, 't1> fn(&'r str, &'s i32, &'t0 i32, std::option::Option>) -> ! {core::macros::internals::assert_failed::}, val: Value(Scalar()) } } bb4: { diff --git a/src/test/ui/hygiene/no_implicit_prelude.stderr b/src/test/ui/hygiene/no_implicit_prelude.stderr index 6cc69a5955d..835ecce94b9 100644 --- a/src/test/ui/hygiene/no_implicit_prelude.stderr +++ b/src/test/ui/hygiene/no_implicit_prelude.stderr @@ -29,5 +29,5 @@ LL | ().clone() error: aborting due to 2 previous errors -Some errors have detailed explanations: E0282, E0433, E0599. -For more information about an error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0433, E0599. +For more information about an error, try `rustc --explain E0433`.