mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Auto merge of #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 #14487 [guide]: https://doc.rust-lang.org/edition-guide/rust-2021/reserving-syntax.html
This commit is contained in:
commit
c3ed59ce1c
2 changed files with 48 additions and 1 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,9 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
|
||||||
|f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) };
|
|f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) };
|
||||||
|
|
||||||
match tok.kind() {
|
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));
|
mods.push(do_ws(after, tok));
|
||||||
}
|
}
|
||||||
L_CURLY if is_next(|it| it != R_CURLY, true) => {
|
L_CURLY if is_next(|it| it != R_CURLY, true) => {
|
||||||
|
|
Loading…
Reference in a new issue