From 090a59970df049bcb3d8c232b6ea6d77101c9853 Mon Sep 17 00:00:00 2001 From: lf- Date: Tue, 15 Dec 2020 01:05:20 -0800 Subject: 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!(""); } ``` --- crates/hir_expand/src/builtin_macro.rs | 15 +++++++++++++++ crates/hir_expand/src/name.rs | 2 ++ 2 files changed, 17 insertions(+) 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! { // format_args_nl only differs in that it adds a newline in the end, // so we use the same stub expansion for now (format_args_nl, FormatArgsNl) => format_args_expand, + (llvm_asm, LlvmAsm) => asm_expand, + (asm, Asm) => asm_expand, EAGER: (compile_error, CompileError) => compile_error_expand, @@ -271,6 +273,19 @@ fn format_args_expand( ExpandResult::ok(expanded) } +fn asm_expand( + _db: &dyn AstDatabase, + _id: LazyMacroId, + _tt: &tt::Subtree, +) -> ExpandResult { + // both asm and llvm_asm don't return anything, so we can expand them to nothing, + // for now + let expanded = quote! { + () + }; + ExpandResult::ok(expanded) +} + fn unquote_str(lit: &tt::Literal) -> Option { let lit = ast::make::tokens::literal(&lit.to_string()); let token = ast::String::cast(lit)?; diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs index 6ec5ca0a9..69d8e6803 100644 --- a/crates/hir_expand/src/name.rs +++ b/crates/hir_expand/src/name.rs @@ -199,6 +199,8 @@ pub mod known { format_args_nl, env, option_env, + llvm_asm, + asm, // Builtin derives Copy, Clone, -- cgit v1.2.3