]> git.lizzy.rs Git - rust.git/commitdiff
Resolve `macro-error` diagnostics on asm & llvm_asm
authorlf- <lf-@users.noreply.github.com>
Tue, 15 Dec 2020 09:05:20 +0000 (01:05 -0800)
committerlf- <lf-@users.noreply.github.com>
Tue, 15 Dec 2020 09:06:53 +0000 (01:06 -0800)
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
crates/hir_expand/src/name.rs

index 8db8c7d0c0298ab795f98f3db3ce97354ae760de..b1b432ded2c95235e9bb9c25be012c080f5240e7 100644 (file)
@@ -95,6 +95,8 @@ pub fn find_builtin_macro(
     // 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<tt::Subtree> {
+    // 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<String> {
     let lit = ast::make::tokens::literal(&lit.to_string());
     let token = ast::String::cast(lit)?;
index 6ec5ca0a97e84335cd162eb4d1702b5d458e34f2..69d8e680394578370fffaac14cc9bdab039216a0 100644 (file)
@@ -199,6 +199,8 @@ macro_rules! known_names {
         format_args_nl,
         env,
         option_env,
+        llvm_asm,
+        asm,
         // Builtin derives
         Copy,
         Clone,