11use ide_db:: { base_db:: FileId , source_change:: SourceChange } ;
22use itertools:: Itertools ;
3- use syntax:: { ast, AstNode , SyntaxKind , SyntaxNode } ;
3+ use syntax:: { ast, AstNode , SyntaxNode } ;
44use text_edit:: TextEdit ;
55
66use crate :: { fix, Diagnostic , DiagnosticCode } ;
@@ -16,7 +16,7 @@ pub(crate) fn useless_braces(
1616 let use_tree_list = ast:: UseTreeList :: cast ( node. clone ( ) ) ?;
1717 if let Some ( ( single_use_tree, ) ) = use_tree_list. use_trees ( ) . collect_tuple ( ) {
1818 // If there is a `self` inside the bracketed `use`, don't show diagnostic.
19- if single_use_tree. syntax ( ) . first_token ( ) . unwrap ( ) . kind ( ) == SyntaxKind :: SELF_KW {
19+ if single_use_tree. path ( ) ? . segment ( ) ? . self_token ( ) . is_some ( ) {
2020 return Some ( ( ) ) ;
2121 }
2222
@@ -53,7 +53,10 @@ pub(crate) fn useless_braces(
5353
5454#[ cfg( test) ]
5555mod tests {
56- use crate :: tests:: { check_diagnostics, check_fix} ;
56+ use crate :: {
57+ tests:: { check_diagnostics, check_diagnostics_with_config, check_fix} ,
58+ DiagnosticsConfig ,
59+ } ;
5760
5861 #[ test]
5962 fn test_check_unnecessary_braces_in_use_statement ( ) {
@@ -100,6 +103,16 @@ use a::{self as cool_name};
100103
101104mod a {
102105}
106+ "# ,
107+ ) ;
108+
109+ let mut config = DiagnosticsConfig :: test_sample ( ) ;
110+ config. disabled . insert ( "syntax-error" . to_string ( ) ) ;
111+ check_diagnostics_with_config (
112+ config,
113+ r#"
114+ mod a { pub mod b {} }
115+ use a::{b::self};
103116"# ,
104117 ) ;
105118 check_fix (
0 commit comments