Skip to content

Commit 54e8973

Browse files
committed
Cover disable diagnostic from case with invalid syntax
1 parent fe65eab commit 54e8973

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

crates/ide-diagnostics/src/handlers/useless_braces.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ide_db::{base_db::FileId, source_change::SourceChange};
22
use itertools::Itertools;
3-
use syntax::{ast, AstNode, SyntaxKind, SyntaxNode};
3+
use syntax::{ast, AstNode, SyntaxNode};
44
use text_edit::TextEdit;
55

66
use 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)]
5555
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+
};
5760

5861
#[test]
5962
fn test_check_unnecessary_braces_in_use_statement() {
@@ -100,6 +103,16 @@ use a::{self as cool_name};
100103
101104
mod 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

Comments
 (0)