From 54e897368d88650b2990aa62ba39dfee0a4f970c Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Wed, 5 Jul 2023 19:31:37 +0200 Subject: [PATCH] Cover disable diagnostic from case with invalid syntax --- .../src/handlers/useless_braces.rs | 19 ++++++++++++++++--- 1 file 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() { @@ -100,6 +103,16 @@ use a::{self as cool_name}; 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(