about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_builtin_macros')
-rw-r--r--compiler/rustc_builtin_macros/src/assert.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/edition_panic.rs (renamed from compiler/rustc_builtin_macros/src/panic.rs)25
-rw-r--r--compiler/rustc_builtin_macros/src/lib.rs7
3 files changed, 28 insertions, 6 deletions
diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs
index 1e2646e4d34..9a45dec55f3 100644
--- a/compiler/rustc_builtin_macros/src/assert.rs
+++ b/compiler/rustc_builtin_macros/src/assert.rs
@@ -1,4 +1,4 @@
-use crate::panic::use_panic_2021;
+use crate::edition_panic::use_panic_2021;
 use rustc_ast::ptr::P;
 use rustc_ast::token;
 use rustc_ast::tokenstream::{DelimSpan, TokenStream};
diff --git a/compiler/rustc_builtin_macros/src/panic.rs b/compiler/rustc_builtin_macros/src/edition_panic.rs
index 54ab596bf3e..518b88dec6a 100644
--- a/compiler/rustc_builtin_macros/src/panic.rs
+++ b/compiler/rustc_builtin_macros/src/edition_panic.rs
@@ -20,8 +20,29 @@ pub fn expand_panic<'cx>(
     sp: Span,
     tts: TokenStream,
 ) -> Box<dyn MacResult + 'cx> {
-    let panic = if use_panic_2021(sp) { sym::panic_2021 } else { sym::panic_2015 };
+    let mac = if use_panic_2021(sp) { sym::panic_2021 } else { sym::panic_2015 };
+    expand(mac, cx, sp, tts)
+}
 
+// This expands to either
+// - `$crate::panic::unreachable_2015!(...)` or
+// - `$crate::panic::unreachable_2021!(...)`
+// depending on the edition.
+pub fn expand_unreachable<'cx>(
+    cx: &'cx mut ExtCtxt<'_>,
+    sp: Span,
+    tts: TokenStream,
+) -> Box<dyn MacResult + 'cx> {
+    let mac = if use_panic_2021(sp) { sym::unreachable_2021 } else { sym::unreachable_2015 };
+    expand(mac, cx, sp, tts)
+}
+
+fn expand<'cx>(
+    mac: rustc_span::Symbol,
+    cx: &'cx mut ExtCtxt<'_>,
+    sp: Span,
+    tts: TokenStream,
+) -> Box<dyn MacResult + 'cx> {
     let sp = cx.with_call_site_ctxt(sp);
 
     MacEager::expr(
@@ -31,7 +52,7 @@ pub fn expand_panic<'cx>(
                 path: Path {
                     span: sp,
                     segments: cx
-                        .std_path(&[sym::panic, panic])
+                        .std_path(&[sym::panic, mac])
                         .into_iter()
                         .map(|ident| PathSegment::from_ident(ident))
                         .collect(),
diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs
index 6c16c285492..98c94dfc686 100644
--- a/compiler/rustc_builtin_macros/src/lib.rs
+++ b/compiler/rustc_builtin_macros/src/lib.rs
@@ -31,12 +31,12 @@ mod concat_bytes;
 mod concat_idents;
 mod derive;
 mod deriving;
+mod edition_panic;
 mod env;
 mod format;
 mod format_foreign;
 mod global_allocator;
 mod log_syntax;
-mod panic;
 mod source_util;
 mod test;
 mod trace_macros;
@@ -82,8 +82,9 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
         log_syntax: log_syntax::expand_log_syntax,
         module_path: source_util::expand_mod,
         option_env: env::expand_option_env,
-        core_panic: panic::expand_panic,
-        std_panic: panic::expand_panic,
+        core_panic: edition_panic::expand_panic,
+        std_panic: edition_panic::expand_panic,
+        unreachable: edition_panic::expand_unreachable,
         stringify: source_util::expand_stringify,
         trace_macros: trace_macros::expand_trace_macros,
     }