Skip to content

Commit 551bf65

Browse files
committed
Keep parens around in remove-dbg for range expressions
1 parent 3182c06 commit 551bf65

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

crates/assists/src/handlers/remove_dbg.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) -
9393
if macro_contents.len() < 2 {
9494
return false;
9595
}
96+
let mut macro_contents = macro_contents.into_iter().peekable();
9697
let mut unpaired_brackets_in_contents = Vec::new();
97-
for element in macro_contents {
98+
while let Some(element) = macro_contents.next() {
9899
match element.kind() {
99100
T!['('] | T!['['] | T!['{'] => unpaired_brackets_in_contents.push(element),
100101
T![')'] => {
@@ -118,12 +119,13 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) -
118119
symbol_kind => {
119120
let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty();
120121
if symbol_not_in_bracket
121-
// paths
122-
&& symbol_kind != SyntaxKind::COLON
123-
// field/method access
124-
&& symbol_kind != SyntaxKind::DOT
125-
// try operator
126-
&& symbol_kind != SyntaxKind::QUESTION
122+
&& symbol_kind != SyntaxKind::COLON // paths
123+
&& (symbol_kind != SyntaxKind::DOT // field/method access
124+
|| macro_contents // range expressions consist of two SyntaxKind::Dot in macro invocations
125+
.peek()
126+
.map(|element| element.kind() == SyntaxKind::DOT)
127+
.unwrap_or(false))
128+
&& symbol_kind != SyntaxKind::QUESTION // try operator
127129
&& (symbol_kind.is_punct() || symbol_kind == SyntaxKind::AS_KW)
128130
{
129131
return true;
@@ -347,7 +349,6 @@ fn main() {
347349
}
348350

349351
#[test]
350-
#[ignore] // FIXME: we encounter SyntaxKind::DOT instead of SyntaxKind::DOT2 causing this to fail
351352
fn test_remove_dbg_range_expr() {
352353
check_assist(
353354
remove_dbg,

0 commit comments

Comments
 (0)