Skip to content

Commit c3ed59c

Browse files
committed
Auto merge of rust-lang#14493 - lowr:fix/ws-between-text-and-pound, r=Veykril
fix: insert whitespace between text and pound Because `text#`, `text"..."`, and `text'...'` are [reserved syntax since Rust 2021][guide]. Note that the latter two are already handled correctly. Fixes rust-lang#14487 [guide]: https://doc.rust-lang.org/edition-guide/rust-2021/reserving-syntax.html
2 parents af30656 + 0df9fb2 commit c3ed59c

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

crates/ide-assists/src/handlers/inline_macro.rs

+45
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,49 @@ fn f() { if true{}; }
254254
"#,
255255
)
256256
}
257+
258+
#[test]
259+
fn whitespace_between_text_and_pound() {
260+
check_assist(
261+
inline_macro,
262+
r#"
263+
macro_rules! foo {
264+
() => {
265+
cfg_if! {
266+
if #[cfg(test)] {
267+
1;
268+
} else {
269+
1;
270+
}
271+
}
272+
}
273+
}
274+
fn main() {
275+
$0foo!();
276+
}
277+
"#,
278+
r#"
279+
macro_rules! foo {
280+
() => {
281+
cfg_if! {
282+
if #[cfg(test)] {
283+
1;
284+
} else {
285+
1;
286+
}
287+
}
288+
}
289+
}
290+
fn main() {
291+
cfg_if!{
292+
if #[cfg(test)]{
293+
1;
294+
}else {
295+
1;
296+
}
297+
};
298+
}
299+
"#,
300+
);
301+
}
257302
}

crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
6060
|f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) };
6161

6262
match tok.kind() {
63-
k if is_text(k) && is_next(|it| !it.is_punct() || it == UNDERSCORE, false) => {
63+
k if is_text(k)
64+
&& is_next(|it| !it.is_punct() || matches!(it, T![_] | T![#]), false) =>
65+
{
6466
mods.push(do_ws(after, tok));
6567
}
6668
L_CURLY if is_next(|it| it != R_CURLY, true) => {

0 commit comments

Comments
 (0)