diff options
| author | bohan <bohan-zhang@foxmail.com> | 2024-03-12 10:55:17 +0800 | 
|---|---|---|
| committer | bohan <bohan-zhang@foxmail.com> | 2024-03-13 16:11:16 +0800 | 
| commit | 8fcdf54a6b98c129e951caf3a97cbf20db677ee3 (patch) | |
| tree | f34b8d1a37fdbe0e539f2c38e91b74a4358d98ef /compiler/rustc_builtin_macros/src/compile_error.rs | |
| parent | 5a6c1aa2bccfcbfa42f486a54c09bd698378faef (diff) | |
| download | rust-8fcdf54a6b98c129e951caf3a97cbf20db677ee3.tar.gz rust-8fcdf54a6b98c129e951caf3a97cbf20db677ee3.zip | |
delay expand macro bang when there has indeterminate path
Diffstat (limited to 'compiler/rustc_builtin_macros/src/compile_error.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/compile_error.rs | 14 | 
1 files changed, 9 insertions, 5 deletions
| diff --git a/compiler/rustc_builtin_macros/src/compile_error.rs b/compiler/rustc_builtin_macros/src/compile_error.rs index b4455d7823f..2f2a87fc9aa 100644 --- a/compiler/rustc_builtin_macros/src/compile_error.rs +++ b/compiler/rustc_builtin_macros/src/compile_error.rs @@ -1,22 +1,26 @@ // The compiler code necessary to support the compile_error! extension. use rustc_ast::tokenstream::TokenStream; -use rustc_expand::base::{get_single_str_from_tts, DummyResult, ExtCtxt, MacResult}; +use rustc_expand::base::get_single_str_from_tts; +use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult}; use rustc_span::Span; pub fn expand_compile_error<'cx>( cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream, -) -> Box<dyn MacResult + 'cx> { - let var = match get_single_str_from_tts(cx, sp, tts, "compile_error!") { +) -> MacroExpanderResult<'cx> { + let ExpandResult::Ready(mac) = get_single_str_from_tts(cx, sp, tts, "compile_error!") else { + return ExpandResult::Retry(()); + }; + let var = match mac { Ok(var) => var, - Err(guar) => return DummyResult::any(sp, guar), + Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)), }; #[expect(rustc::diagnostic_outside_of_impl, reason = "diagnostic message is specified by user")] #[expect(rustc::untranslatable_diagnostic, reason = "diagnostic message is specified by user")] let guar = cx.dcx().span_err(sp, var.to_string()); - DummyResult::any(sp, guar) + ExpandResult::Ready(DummyResult::any(sp, guar)) } | 
