about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorLoïc BRANSTETT <lolo.branstett@numericable.fr>2022-01-21 23:04:06 +0100
committerLoïc BRANSTETT <lolo.branstett@numericable.fr>2022-01-31 17:09:31 +0100
commit565710b33cb20c901b8b3371d1364cf7fb11e79b (patch)
treeea8b01a50153f7188172d0a924b86fa30471d4a2 /compiler
parent86f5e177bca8121e1edc9864023a8ea61acf9034 (diff)
downloadrust-565710b33cb20c901b8b3371d1364cf7fb11e79b.tar.gz
rust-565710b33cb20c901b8b3371d1364cf7fb11e79b.zip
Fix invalid special casing of the unreachable! macro
Diffstat (limited to 'compiler')
-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
-rw-r--r--compiler/rustc_span/src/symbol.rs5
4 files changed, 33 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,
     }
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 757c430e799..7068b86572f 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -1437,7 +1437,12 @@ symbols! {
         unmarked_api,
         unpin,
         unreachable,
+        unreachable_2015,
+        unreachable_2015_macro,
+        unreachable_2021,
+        unreachable_2021_macro,
         unreachable_code,
+        unreachable_display,
         unreachable_macro,
         unrestricted_attribute_tokens,
         unsafe_block_in_unsafe_fn,