Skip to content

Commit ea385e5

Browse files
committed
Qualify panic! as core::panic! in non-built-in core macros
Otherwise code like this #![no_implicit_prelude] fn main() { ::std::todo!(); ::std::unimplemented!(); } will fail to compile, which is unfortunate and presumably unintended. This changes many invocations of `panic!` in a `macro_rules!` definition to invocations of `$crate::panic!`, which makes the invocations hygienic. Note that this does not make the built-in macro `assert!` hygienic.
1 parent 7ee8687 commit ea385e5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

core/src/macros/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ macro_rules! assert_eq {
4545
// The reborrows below are intentional. Without them, the stack slot for the
4646
// borrow is initialized even before the values are compared, leading to a
4747
// noticeable slow down.
48-
panic!(r#"assertion failed: `(left == right)`
48+
$crate::panic!(r#"assertion failed: `(left == right)`
4949
left: `{:?}`,
5050
right: `{:?}`"#, &*left_val, &*right_val)
5151
}
@@ -59,7 +59,7 @@ macro_rules! assert_eq {
5959
// The reborrows below are intentional. Without them, the stack slot for the
6060
// borrow is initialized even before the values are compared, leading to a
6161
// noticeable slow down.
62-
panic!(r#"assertion failed: `(left == right)`
62+
$crate::panic!(r#"assertion failed: `(left == right)`
6363
left: `{:?}`,
6464
right: `{:?}`: {}"#, &*left_val, &*right_val,
6565
$crate::format_args!($($arg)+))
@@ -96,7 +96,7 @@ macro_rules! assert_ne {
9696
// The reborrows below are intentional. Without them, the stack slot for the
9797
// borrow is initialized even before the values are compared, leading to a
9898
// noticeable slow down.
99-
panic!(r#"assertion failed: `(left != right)`
99+
$crate::panic!(r#"assertion failed: `(left != right)`
100100
left: `{:?}`,
101101
right: `{:?}`"#, &*left_val, &*right_val)
102102
}
@@ -110,7 +110,7 @@ macro_rules! assert_ne {
110110
// The reborrows below are intentional. Without them, the stack slot for the
111111
// borrow is initialized even before the values are compared, leading to a
112112
// noticeable slow down.
113-
panic!(r#"assertion failed: `(left != right)`
113+
$crate::panic!(r#"assertion failed: `(left != right)`
114114
left: `{:?}`,
115115
right: `{:?}`: {}"#, &*left_val, &*right_val,
116116
$crate::format_args!($($arg)+))
@@ -468,7 +468,7 @@ macro_rules! writeln {
468468
///
469469
/// # Panics
470470
///
471-
/// This will always [`panic!`]
471+
/// This will always [`panic!`].
472472
///
473473
/// # Examples
474474
///
@@ -502,13 +502,13 @@ macro_rules! writeln {
502502
#[stable(feature = "rust1", since = "1.0.0")]
503503
macro_rules! unreachable {
504504
() => ({
505-
panic!("internal error: entered unreachable code")
505+
$crate::panic!("internal error: entered unreachable code")
506506
});
507507
($msg:expr $(,)?) => ({
508508
$crate::unreachable!("{}", $msg)
509509
});
510510
($fmt:expr, $($arg:tt)*) => ({
511-
panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
511+
$crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
512512
});
513513
}
514514

@@ -586,8 +586,8 @@ macro_rules! unreachable {
586586
#[macro_export]
587587
#[stable(feature = "rust1", since = "1.0.0")]
588588
macro_rules! unimplemented {
589-
() => (panic!("not implemented"));
590-
($($arg:tt)+) => (panic!("not implemented: {}", $crate::format_args!($($arg)+)));
589+
() => ($crate::panic!("not implemented"));
590+
($($arg:tt)+) => ($crate::panic!("not implemented: {}", $crate::format_args!($($arg)+)));
591591
}
592592

593593
/// Indicates unfinished code.
@@ -647,8 +647,8 @@ macro_rules! unimplemented {
647647
#[macro_export]
648648
#[stable(feature = "todo_macro", since = "1.40.0")]
649649
macro_rules! todo {
650-
() => (panic!("not yet implemented"));
651-
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
650+
() => ($crate::panic!("not yet implemented"));
651+
($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
652652
}
653653

654654
/// Definitions of built-in macros.

0 commit comments

Comments
 (0)