1
1
use ide_db:: { base_db:: FileId , source_change:: SourceChange } ;
2
2
use itertools:: Itertools ;
3
- use syntax:: { ast, AstNode , SyntaxKind , SyntaxNode } ;
3
+ use syntax:: { ast, AstNode , SyntaxNode } ;
4
4
use text_edit:: TextEdit ;
5
5
6
6
use crate :: { fix, Diagnostic , DiagnosticCode } ;
@@ -16,7 +16,7 @@ pub(crate) fn useless_braces(
16
16
let use_tree_list = ast:: UseTreeList :: cast ( node. clone ( ) ) ?;
17
17
if let Some ( ( single_use_tree, ) ) = use_tree_list. use_trees ( ) . collect_tuple ( ) {
18
18
// 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 ( ) {
20
20
return Some ( ( ) ) ;
21
21
}
22
22
@@ -53,7 +53,10 @@ pub(crate) fn useless_braces(
53
53
54
54
#[ cfg( test) ]
55
55
mod 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
+ } ;
57
60
58
61
#[ test]
59
62
fn test_check_unnecessary_braces_in_use_statement ( ) {
@@ -100,6 +103,16 @@ use a::{self as cool_name};
100
103
101
104
mod a {
102
105
}
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};
103
116
"# ,
104
117
) ;
105
118
check_fix (
0 commit comments