@@ -3,12 +3,11 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
33use clippy_utils:: msrvs:: Msrv ;
44use clippy_utils:: source:: { HasSession , IntoSpan as _, SpanRangeExt , snippet, snippet_block_with_applicability} ;
55use clippy_utils:: { can_use_if_let_chains, span_contains_cfg, span_contains_non_whitespace, sym, tokenize_with_text} ;
6- use rustc_ast:: BinOpKind ;
6+ use rustc_ast:: { BinOpKind , MetaItemInner } ;
77use rustc_errors:: Applicability ;
8- use rustc_hir:: attrs:: { AttributeKind , LintAttributeKind } ;
9- use rustc_hir:: { Attribute , Block , Expr , ExprKind , StmtKind } ;
8+ use rustc_hir:: { Block , Expr , ExprKind , StmtKind } ;
109use rustc_lexer:: TokenKind ;
11- use rustc_lint:: { LateContext , LateLintPass } ;
10+ use rustc_lint:: { LateContext , LateLintPass , Level } ;
1211use rustc_session:: impl_lint_pass;
1312use rustc_span:: { BytePos , Span , Symbol } ;
1413
@@ -238,24 +237,19 @@ impl CollapsibleIf {
238237 !span_contains_non_whitespace ( cx, span, self . lint_commented_code )
239238 } ,
240239
241- [ Attribute :: Parsed ( AttributeKind :: LintAttributes ( sub_attrs) ) ] => {
242- sub_attrs
243- . into_iter ( )
244- . filter ( |attr| attr. kind == LintAttributeKind :: Expect )
245- . flat_map ( |attr| attr. lint_instances . iter ( ) . map ( |group| ( attr. attr_span , group) ) )
246- . filter ( |( _, lint_id) | {
247- lint_id. tool_is_named ( sym:: clippy)
248- && ( expected_lint_name == lint_id. lint_name ( )
249- || [ expected_lint_name, sym:: style, sym:: all]
250- . contains ( & lint_id. original_name_without_tool ( ) ) )
251- } )
252- . any ( |( attr_span, _) | {
253- // There is an `expect` attribute -- check that there is no _other_ significant text
254- let span_before_attr = inner_if. span . split_at ( 1 ) . 1 . until ( attr_span) ;
255- let span_after_attr = attr_span. between ( inner_if_expr. span ) ;
256- !span_contains_non_whitespace ( cx, span_before_attr, self . lint_commented_code )
257- && !span_contains_non_whitespace ( cx, span_after_attr, self . lint_commented_code )
258- } )
240+ [ attr]
241+ if matches ! ( Level :: from_attr( attr) , Some ( ( Level :: Expect , _) ) )
242+ && let Some ( metas) = attr. meta_item_list ( )
243+ && let Some ( MetaItemInner :: MetaItem ( meta_item) ) = metas. first ( )
244+ && let [ tool, lint_name] = meta_item. path . segments . as_slice ( )
245+ && tool. ident . name == sym:: clippy
246+ && [ expected_lint_name, sym:: style, sym:: all] . contains ( & lint_name. ident . name ) =>
247+ {
248+ // There is an `expect` attribute -- check that there is no _other_ significant text
249+ let span_before_attr = inner_if. span . split_at ( 1 ) . 1 . until ( attr. span ( ) ) ;
250+ let span_after_attr = attr. span ( ) . between ( inner_if_expr. span ) ;
251+ !span_contains_non_whitespace ( cx, span_before_attr, self . lint_commented_code )
252+ && !span_contains_non_whitespace ( cx, span_after_attr, self . lint_commented_code )
259253 } ,
260254
261255 // There are other attributes, which are significant tokens -- check failed
0 commit comments