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>
This commit is contained in:
bors[bot] 2020-10-06 11:36:25 +00:00 committed by GitHub
commit 69512dae26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
use syntax::{
ast::{self, AstNode},
SyntaxElement, TextRange, TextSize, T,
SyntaxElement, SyntaxKind, TextRange, TextSize, T,
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
@ -117,7 +117,10 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) -
}
symbol_kind => {
let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty();
if symbol_not_in_bracket && symbol_kind.is_punct() {
if symbol_not_in_bracket
&& symbol_kind != SyntaxKind::COLON
&& symbol_kind.is_punct()
{
return true;
}
}
@ -159,6 +162,8 @@ fn foo(n: usize) {
}
",
);
check_assist(remove_dbg, "<|>dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()");
}
#[test]