Skip to content

Commit 69512da

Browse files
Merge #6147
6147: Do not leave braces for colons in dbg! r=matklad a=SomeoneToIgnore Tweak remove dbg heuristics a bit to remove braces when colons (`:`) are used in the non-leaf dbg expressions. Before: `dbg!(Foo::foo_test()).bar()` -> `(Foo::foo_test()).bar()` After: `dbg!(Foo::foo_test()).bar()` -> `Foo::foo_test().bar()` Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2 parents cb78c40 + af4ae86 commit 69512da

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

crates/assists/src/handlers/remove_dbg.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use syntax::{
22
ast::{self, AstNode},
3-
SyntaxElement, TextRange, TextSize, T,
3+
SyntaxElement, SyntaxKind, TextRange, TextSize, T,
44
};
55

66
use crate::{AssistContext, AssistId, AssistKind, Assists};
@@ -117,7 +117,10 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) -
117117
}
118118
symbol_kind => {
119119
let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty();
120-
if symbol_not_in_bracket && symbol_kind.is_punct() {
120+
if symbol_not_in_bracket
121+
&& symbol_kind != SyntaxKind::COLON
122+
&& symbol_kind.is_punct()
123+
{
121124
return true;
122125
}
123126
}
@@ -159,6 +162,8 @@ fn foo(n: usize) {
159162
}
160163
",
161164
);
165+
166+
check_assist(remove_dbg, "<|>dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()");
162167
}
163168

164169
#[test]

0 commit comments

Comments
 (0)