From dca8f612d0522aecad27f0f5053987b3e5c6b3e2 Mon Sep 17 00:00:00 2001 From: Jake Heinz Date: Sat, 27 Nov 2021 02:22:21 +0000 Subject: [PATCH] ide: fix expansion for 'as _' --- crates/ide/src/expand_macro.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index 57c078ef57d..ee49732240e 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -176,6 +176,10 @@ fn insert_whitespaces(syn: SyntaxNode) -> String { res.push_str(token.text()); res.push(' '); } + AS_KW => { + res.push_str(token.text()); + res.push(' '); + } T![;] => { res.push_str(";\n"); res.extend(iter::repeat(" ").take(2 * indent)); @@ -210,6 +214,23 @@ mod tests { expect.assert_eq(&actual); } + #[test] + fn macro_expand_as_keyword() { + check( + r#" +macro_rules! bar { + ($i:tt) => { $i as _ } +} +fn main() { + let x: u64 = ba$0r!(5i64); +} +"#, + expect![[r#" + bar + 5i64 as _"#]], + ); + } + #[test] fn macro_expand_recursive_expansion() { check(