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