aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-30 07:45:33 +0000
committerGitHub <[email protected]>2020-12-30 07:45:33 +0000
commite7d2b5888b8a7e632ae9080108ccbc450316fd86 (patch)
tree721f9183ad55b80a77b1ae787e6e5f299def28ef /crates/ide/src
parent848e817f603ed12e065bc3057d12e04b481fb5bb (diff)
parentddbf484acf15efd73b61ac80a941730b507c01de (diff)
Merge #7088
7088: Smarter bracketed `use` diagnostic r=lnicola a=AdnoC Closes https://github.com/rust-analyzer/rust-analyzer/issues/4531 Makes it so that if a bracketed use statement contains a comment inside the braces, no "Unnecessary braces in use statement" diagnostic is shown. Co-authored-by: AdnoC <[email protected]>
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/diagnostics.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 038273750..79d126ff2 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -199,6 +199,12 @@ fn check_unnecessary_braces_in_use_statement(
199) -> Option<()> { 199) -> Option<()> {
200 let use_tree_list = ast::UseTreeList::cast(node.clone())?; 200 let use_tree_list = ast::UseTreeList::cast(node.clone())?;
201 if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() { 201 if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() {
202 // If there is a comment inside the bracketed `use`,
203 // assume it is a commented out module path and don't show diagnostic.
204 if use_tree_list.has_inner_comment() {
205 return Some(());
206 }
207
202 let use_range = use_tree_list.syntax().text_range(); 208 let use_range = use_tree_list.syntax().text_range();
203 let edit = 209 let edit =
204 text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(&single_use_tree) 210 text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(&single_use_tree)
@@ -638,6 +644,22 @@ mod a {
638} 644}
639"#, 645"#,
640 ); 646 );
647 check_no_diagnostics(
648 r#"
649use a;
650use a::{
651 c,
652 // d::e
653};
654
655mod a {
656 mod c {}
657 mod d {
658 mod e {}
659 }
660}
661"#,
662 );
641 check_fix( 663 check_fix(
642 r" 664 r"
643 mod b {} 665 mod b {}