diff options
| author | Ryo Yoshida <low.ryoshida@gmail.com> | 2023-04-05 20:33:17 +0900 |
|---|---|---|
| committer | Ryo Yoshida <low.ryoshida@gmail.com> | 2023-04-05 20:33:17 +0900 |
| commit | 0df9fb22d8f6dacc01eabb6ff0bd3babcb03e6eb (patch) | |
| tree | 7b138689b8bffe6cc8a1230c65ed047f4ac0e92c | |
| parent | a6464392c15fa8788215d669c4c0b1e46bcadeea (diff) | |
| download | rust-0df9fb22d8f6dacc01eabb6ff0bd3babcb03e6eb.tar.gz rust-0df9fb22d8f6dacc01eabb6ff0bd3babcb03e6eb.zip | |
fix: insert whitespace between text and pound
`text#`, `text"..."`, and `text'...'` are reserved syntax since Rust 2021. Note that the latter two are already handled correctly.
| -rw-r--r-- | crates/ide-assists/src/handlers/inline_macro.rs | 45 | ||||
| -rw-r--r-- | crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs | 4 |
2 files changed, 48 insertions, 1 deletions
diff --git a/crates/ide-assists/src/handlers/inline_macro.rs b/crates/ide-assists/src/handlers/inline_macro.rs index 3fc552306a6..626f2060b23 100644 --- a/crates/ide-assists/src/handlers/inline_macro.rs +++ b/crates/ide-assists/src/handlers/inline_macro.rs @@ -254,4 +254,49 @@ fn f() { if true{}; } "#, ) } + + #[test] + fn whitespace_between_text_and_pound() { + check_assist( + inline_macro, + r#" +macro_rules! foo { + () => { + cfg_if! { + if #[cfg(test)] { + 1; + } else { + 1; + } + } + } +} +fn main() { + $0foo!(); +} +"#, + r#" +macro_rules! foo { + () => { + cfg_if! { + if #[cfg(test)] { + 1; + } else { + 1; + } + } + } +} +fn main() { + cfg_if!{ + if #[cfg(test)]{ + 1; + }else { + 1; + } +}; +} +"#, + ); + } } diff --git a/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs b/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs index 8bc093a85a2..0b0fc669352 100644 --- a/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs +++ b/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs @@ -60,7 +60,9 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode { |f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) }; match tok.kind() { - k if is_text(k) && is_next(|it| !it.is_punct() || it == UNDERSCORE, false) => { + k if is_text(k) + && is_next(|it| !it.is_punct() || matches!(it, T![_] | T![#]), false) => + { mods.push(do_ws(after, tok)); } L_CURLY if is_next(|it| it != R_CURLY, true) => { |
