aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/builtin_macro.rs
diff options
context:
space:
mode:
authorlf- <[email protected]>2020-12-15 09:05:20 +0000
committerlf- <[email protected]>2020-12-15 09:06:53 +0000
commit090a59970df049bcb3d8c232b6ea6d77101c9853 (patch)
treefefe6eeeb5f1007b50260b6b812fd596faadaf20 /crates/hir_expand/src/builtin_macro.rs
parent34f7b5383af61d8896c97e407888cfde2ba35350 (diff)
Resolve `macro-error` diagnostics on asm & llvm_asm
We currently stub these out as returning unit. This fixes spurious RA diagnostics in the following: ```rust unsafe { asm!(""); llvm_asm!(""); } ```
Diffstat (limited to 'crates/hir_expand/src/builtin_macro.rs')
-rw-r--r--crates/hir_expand/src/builtin_macro.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 8db8c7d0c..b1b432ded 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -95,6 +95,8 @@ register_builtin! {
95 // format_args_nl only differs in that it adds a newline in the end, 95 // format_args_nl only differs in that it adds a newline in the end,
96 // so we use the same stub expansion for now 96 // so we use the same stub expansion for now
97 (format_args_nl, FormatArgsNl) => format_args_expand, 97 (format_args_nl, FormatArgsNl) => format_args_expand,
98 (llvm_asm, LlvmAsm) => asm_expand,
99 (asm, Asm) => asm_expand,
98 100
99 EAGER: 101 EAGER:
100 (compile_error, CompileError) => compile_error_expand, 102 (compile_error, CompileError) => compile_error_expand,
@@ -271,6 +273,19 @@ fn format_args_expand(
271 ExpandResult::ok(expanded) 273 ExpandResult::ok(expanded)
272} 274}
273 275
276fn asm_expand(
277 _db: &dyn AstDatabase,
278 _id: LazyMacroId,
279 _tt: &tt::Subtree,
280) -> ExpandResult<tt::Subtree> {
281 // both asm and llvm_asm don't return anything, so we can expand them to nothing,
282 // for now
283 let expanded = quote! {
284 ()
285 };
286 ExpandResult::ok(expanded)
287}
288
274fn unquote_str(lit: &tt::Literal) -> Option<String> { 289fn unquote_str(lit: &tt::Literal) -> Option<String> {
275 let lit = ast::make::tokens::literal(&lit.to_string()); 290 let lit = ast::make::tokens::literal(&lit.to_string());
276 let token = ast::String::cast(lit)?; 291 let token = ast::String::cast(lit)?;