Skip to content

Commit a9d1920

Browse files
bors[bot]lf-
andauthored
Merge #6889
6889: Resolve `macro-error` diagnostics on asm & llvm_asm r=matklad a=lf- We currently stub these out as returning unit. This fixes spurious RA `macro-error` diagnostics introduced somewhere around 0.2.400 in the following: ```rust unsafe { asm!(""); llvm_asm!(""); } ``` I'd ideally like to write a unit test for this, but I'm not familiar with where the tests for `hir_expand` are. Thanks to @edwin0cheng for help on resolving this issue. Co-authored-by: lf- <[email protected]>
2 parents 95f3dcd + 090a599 commit a9d1920

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/hir_expand/src/builtin_macro.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ register_builtin! {
9595
// format_args_nl only differs in that it adds a newline in the end,
9696
// so we use the same stub expansion for now
9797
(format_args_nl, FormatArgsNl) => format_args_expand,
98+
(llvm_asm, LlvmAsm) => asm_expand,
99+
(asm, Asm) => asm_expand,
98100

99101
EAGER:
100102
(compile_error, CompileError) => compile_error_expand,
@@ -271,6 +273,19 @@ fn format_args_expand(
271273
ExpandResult::ok(expanded)
272274
}
273275

276+
fn 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+
274289
fn unquote_str(lit: &tt::Literal) -> Option<String> {
275290
let lit = ast::make::tokens::literal(&lit.to_string());
276291
let token = ast::String::cast(lit)?;

crates/hir_expand/src/name.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ pub mod known {
199199
format_args_nl,
200200
env,
201201
option_env,
202+
llvm_asm,
203+
asm,
202204
// Builtin derives
203205
Copy,
204206
Clone,

0 commit comments

Comments
 (0)