Unnamed repository; edit this file 'description' to name the repository.
Cover disable diagnostic from case with invalid syntax
AmrDeveloper 2023-07-06
parent fe65eab · commit 54e8973
-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 d9a9c486a3..0aa439f797 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 {}