about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/ide-diagnostics/src/handlers/useless_braces.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/crates/ide-diagnostics/src/handlers/useless_braces.rs b/crates/ide-diagnostics/src/handlers/useless_braces.rs
index d9a9c486a36..0aa439f797a 100644
--- a/crates/ide-diagnostics/src/handlers/useless_braces.rs
+++ b/crates/ide-diagnostics/src/handlers/useless_braces.rs
@@ -1,6 +1,6 @@
 use ide_db::{base_db::FileId, source_change::SourceChange};
 use itertools::Itertools;
-use syntax::{ast, AstNode, SyntaxKind, SyntaxNode};
+use syntax::{ast, AstNode, SyntaxNode};
 use text_edit::TextEdit;
 
 use crate::{fix, Diagnostic, DiagnosticCode};
@@ -16,7 +16,7 @@ pub(crate) fn useless_braces(
     let use_tree_list = ast::UseTreeList::cast(node.clone())?;
     if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() {
         // If there is a `self` inside the bracketed `use`, don't show diagnostic.
-        if single_use_tree.syntax().first_token().unwrap().kind() == SyntaxKind::SELF_KW {
+        if single_use_tree.path()?.segment()?.self_token().is_some() {
             return Some(());
         }
 
@@ -53,7 +53,10 @@ pub(crate) fn useless_braces(
 
 #[cfg(test)]
 mod tests {
-    use crate::tests::{check_diagnostics, check_fix};
+    use crate::{
+        tests::{check_diagnostics, check_diagnostics_with_config, check_fix},
+        DiagnosticsConfig,
+    };
 
     #[test]
     fn test_check_unnecessary_braces_in_use_statement() {
@@ -102,6 +105,16 @@ mod a {
 }
 "#,
         );
+
+        let mut config = DiagnosticsConfig::test_sample();
+        config.disabled.insert("syntax-error".to_string());
+        check_diagnostics_with_config(
+            config,
+            r#"
+mod a { pub mod b {} }
+use a::{b::self};
+"#,
+        );
         check_fix(
             r#"
 mod b {}