Skip to content

Commit 3eba549

Browse files
authored
Rollup merge of rust-lang#78343 - camelid:macros-qualify-panic, r=m-ou-se
Qualify `panic!` as `core::panic!` in non-built-in `core` macros Fixes rust-lang#78333. ----- 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.
2 parents fcffbcf + 922ebf4 commit 3eba549

11 files changed

+437
-448
lines changed

library/core/src/macros/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! assert_eq {
4444
// The reborrows below are intentional. Without them, the stack slot for the
4545
// borrow is initialized even before the values are compared, leading to a
4646
// noticeable slow down.
47-
panic!(r#"assertion failed: `(left == right)`
47+
$crate::panic!(r#"assertion failed: `(left == right)`
4848
left: `{:?}`,
4949
right: `{:?}`"#, &*left_val, &*right_val)
5050
}
@@ -58,7 +58,7 @@ macro_rules! assert_eq {
5858
// The reborrows below are intentional. Without them, the stack slot for the
5959
// borrow is initialized even before the values are compared, leading to a
6060
// noticeable slow down.
61-
panic!(r#"assertion failed: `(left == right)`
61+
$crate::panic!(r#"assertion failed: `(left == right)`
6262
left: `{:?}`,
6363
right: `{:?}`: {}"#, &*left_val, &*right_val,
6464
$crate::format_args!($($arg)+))
@@ -95,7 +95,7 @@ macro_rules! assert_ne {
9595
// The reborrows below are intentional. Without them, the stack slot for the
9696
// borrow is initialized even before the values are compared, leading to a
9797
// noticeable slow down.
98-
panic!(r#"assertion failed: `(left != right)`
98+
$crate::panic!(r#"assertion failed: `(left != right)`
9999
left: `{:?}`,
100100
right: `{:?}`"#, &*left_val, &*right_val)
101101
}
@@ -109,7 +109,7 @@ macro_rules! assert_ne {
109109
// The reborrows below are intentional. Without them, the stack slot for the
110110
// borrow is initialized even before the values are compared, leading to a
111111
// noticeable slow down.
112-
panic!(r#"assertion failed: `(left != right)`
112+
$crate::panic!(r#"assertion failed: `(left != right)`
113113
left: `{:?}`,
114114
right: `{:?}`: {}"#, &*left_val, &*right_val,
115115
$crate::format_args!($($arg)+))
@@ -466,7 +466,7 @@ macro_rules! writeln {
466466
///
467467
/// # Panics
468468
///
469-
/// This will always [`panic!`]
469+
/// This will always [`panic!`].
470470
///
471471
/// # Examples
472472
///
@@ -500,13 +500,13 @@ macro_rules! writeln {
500500
#[stable(feature = "rust1", since = "1.0.0")]
501501
macro_rules! unreachable {
502502
() => ({
503-
panic!("internal error: entered unreachable code")
503+
$crate::panic!("internal error: entered unreachable code")
504504
});
505505
($msg:expr $(,)?) => ({
506506
$crate::unreachable!("{}", $msg)
507507
});
508508
($fmt:expr, $($arg:tt)*) => ({
509-
panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
509+
$crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
510510
});
511511
}
512512

@@ -515,15 +515,15 @@ macro_rules! unreachable {
515515
/// This allows your code to type-check, which is useful if you are prototyping or
516516
/// implementing a trait that requires multiple methods which you don't plan of using all of.
517517
///
518-
/// The difference between `unimplemented!` and [`todo!`](macro.todo.html) is that while `todo!`
518+
/// The difference between `unimplemented!` and [`todo!`] is that while `todo!`
519519
/// conveys an intent of implementing the functionality later and the message is "not yet
520520
/// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
521521
/// Also some IDEs will mark `todo!`s.
522522
///
523523
/// # Panics
524524
///
525-
/// This will always [panic!](macro.panic.html) because `unimplemented!` is just a
526-
/// shorthand for `panic!` with a fixed, specific message.
525+
/// This will always [`panic!`] because `unimplemented!` is just a shorthand for `panic!` with a
526+
/// fixed, specific message.
527527
///
528528
/// Like `panic!`, this macro has a second form for displaying custom values.
529529
///
@@ -584,8 +584,8 @@ macro_rules! unreachable {
584584
#[macro_export]
585585
#[stable(feature = "rust1", since = "1.0.0")]
586586
macro_rules! unimplemented {
587-
() => (panic!("not implemented"));
588-
($($arg:tt)+) => (panic!("not implemented: {}", $crate::format_args!($($arg)+)));
587+
() => ($crate::panic!("not implemented"));
588+
($($arg:tt)+) => ($crate::panic!("not implemented: {}", $crate::format_args!($($arg)+)));
589589
}
590590

591591
/// Indicates unfinished code.
@@ -600,7 +600,7 @@ macro_rules! unimplemented {
600600
///
601601
/// # Panics
602602
///
603-
/// This will always [panic!](macro.panic.html)
603+
/// This will always [`panic!`].
604604
///
605605
/// # Examples
606606
///
@@ -645,8 +645,8 @@ macro_rules! unimplemented {
645645
#[macro_export]
646646
#[stable(feature = "todo_macro", since = "1.40.0")]
647647
macro_rules! todo {
648-
() => (panic!("not yet implemented"));
649-
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
648+
() => ($crate::panic!("not yet implemented"));
649+
($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
650650
}
651651

652652
/// Definitions of built-in macros.

0 commit comments

Comments
 (0)