about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/concat.rs
diff options
context:
space:
mode:
authorbohan <bohan-zhang@foxmail.com>2024-03-12 10:55:17 +0800
committerbohan <bohan-zhang@foxmail.com>2024-03-13 16:11:16 +0800
commit8fcdf54a6b98c129e951caf3a97cbf20db677ee3 (patch)
treef34b8d1a37fdbe0e539f2c38e91b74a4358d98ef /compiler/rustc_builtin_macros/src/concat.rs
parent5a6c1aa2bccfcbfa42f486a54c09bd698378faef (diff)
downloadrust-8fcdf54a6b98c129e951caf3a97cbf20db677ee3.tar.gz
rust-8fcdf54a6b98c129e951caf3a97cbf20db677ee3.zip
delay expand macro bang when there has indeterminate path
Diffstat (limited to 'compiler/rustc_builtin_macros/src/concat.rs')
-rw-r--r--compiler/rustc_builtin_macros/src/concat.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/compiler/rustc_builtin_macros/src/concat.rs b/compiler/rustc_builtin_macros/src/concat.rs
index 0bfb848859b..93a7ac05a9b 100644
--- a/compiler/rustc_builtin_macros/src/concat.rs
+++ b/compiler/rustc_builtin_macros/src/concat.rs
@@ -1,6 +1,7 @@
 use rustc_ast::tokenstream::TokenStream;
 use rustc_ast::{ExprKind, LitKind, UnOp};
-use rustc_expand::base::{get_exprs_from_tts, DummyResult, ExtCtxt, MacEager, MacResult};
+use rustc_expand::base::get_exprs_from_tts;
+use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
 use rustc_session::errors::report_lit_error;
 use rustc_span::symbol::Symbol;
 
@@ -10,10 +11,13 @@ pub fn expand_concat(
     cx: &mut ExtCtxt<'_>,
     sp: rustc_span::Span,
     tts: TokenStream,
-) -> Box<dyn MacResult + 'static> {
-    let es = match get_exprs_from_tts(cx, tts) {
+) -> MacroExpanderResult<'static> {
+    let ExpandResult::Ready(mac) = get_exprs_from_tts(cx, tts) else {
+        return ExpandResult::Retry(());
+    };
+    let es = match mac {
         Ok(es) => es,
-        Err(guar) => return DummyResult::any(sp, guar),
+        Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)),
     };
     let mut accumulator = String::new();
     let mut missing_literal = vec![];
@@ -70,12 +74,13 @@ pub fn expand_concat(
         }
     }
 
-    if !missing_literal.is_empty() {
+    ExpandResult::Ready(if !missing_literal.is_empty() {
         let guar = cx.dcx().emit_err(errors::ConcatMissingLiteral { spans: missing_literal });
-        return DummyResult::any(sp, guar);
+        DummyResult::any(sp, guar)
     } else if let Some(guar) = guar {
-        return DummyResult::any(sp, guar);
-    }
-    let sp = cx.with_def_site_ctxt(sp);
-    MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
+        DummyResult::any(sp, guar)
+    } else {
+        let sp = cx.with_def_site_ctxt(sp);
+        MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))
+    })
 }