@@ -14,8 +14,8 @@ mod utils;
1414
1515use clippy_config:: Conf ;
1616use clippy_config:: msrvs:: { self , Msrv } ;
17- use rustc_ast:: { Attribute , MetaItemInner , MetaItemKind } ;
18- use rustc_hir:: { ImplItem , Item , ItemKind , TraitItem } ;
17+ use rustc_ast:: { self as ast , Attribute , MetaItemInner , MetaItemKind } ;
18+ use rustc_hir:: { ImplItem , Item , TraitItem } ;
1919use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass } ;
2020use rustc_session:: impl_lint_pass;
2121use rustc_span:: sym;
@@ -414,15 +414,7 @@ pub struct Attributes {
414414}
415415
416416impl_lint_pass ! ( Attributes => [
417- ALLOW_ATTRIBUTES ,
418- ALLOW_ATTRIBUTES_WITHOUT_REASON ,
419417 INLINE_ALWAYS ,
420- DEPRECATED_SEMVER ,
421- USELESS_ATTRIBUTE ,
422- BLANKET_CLIPPY_RESTRICTION_LINTS ,
423- SHOULD_PANIC_WITHOUT_EXPECT ,
424- MIXED_ATTRIBUTES_STYLE ,
425- DUPLICATED_ATTRIBUTES ,
426418] ) ;
427419
428420impl Attributes {
@@ -434,53 +426,11 @@ impl Attributes {
434426}
435427
436428impl < ' tcx > LateLintPass < ' tcx > for Attributes {
437- fn check_crate ( & mut self , cx : & LateContext < ' tcx > ) {
438- blanket_clippy_restriction_lints:: check_command_line ( cx) ;
439- duplicated_attributes:: check ( cx, cx. tcx . hir ( ) . krate_attrs ( ) ) ;
440- }
441-
442- fn check_attribute ( & mut self , cx : & LateContext < ' tcx > , attr : & ' tcx Attribute ) {
443- if let Some ( items) = & attr. meta_item_list ( ) {
444- if let Some ( ident) = attr. ident ( ) {
445- if is_lint_level ( ident. name , attr. id ) {
446- blanket_clippy_restriction_lints:: check ( cx, ident. name , items) ;
447- }
448- if matches ! ( ident. name, sym:: allow) && self . msrv . meets ( msrvs:: LINT_REASONS_STABILIZATION ) {
449- allow_attributes:: check ( cx, attr) ;
450- }
451- if matches ! ( ident. name, sym:: allow | sym:: expect) && self . msrv . meets ( msrvs:: LINT_REASONS_STABILIZATION )
452- {
453- allow_attributes_without_reason:: check ( cx, ident. name , items, attr) ;
454- }
455- if items. is_empty ( ) || !attr. has_name ( sym:: deprecated) {
456- return ;
457- }
458- for item in items {
459- if let MetaItemInner :: MetaItem ( mi) = & item
460- && let MetaItemKind :: NameValue ( lit) = & mi. kind
461- && mi. has_name ( sym:: since)
462- {
463- deprecated_semver:: check ( cx, item. span ( ) , lit) ;
464- }
465- }
466- }
467- }
468- if attr. has_name ( sym:: should_panic) {
469- should_panic_without_expect:: check ( cx, attr) ;
470- }
471- }
472-
473429 fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' _ > ) {
474430 let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
475431 if is_relevant_item ( cx, item) {
476432 inline_always:: check ( cx, item. span , item. ident . name , attrs) ;
477433 }
478- match item. kind {
479- ItemKind :: ExternCrate ( ..) | ItemKind :: Use ( ..) => useless_attribute:: check ( cx, item, attrs) ,
480- _ => { } ,
481- }
482- mixed_attributes_style:: check ( cx, item. span , attrs) ;
483- duplicated_attributes:: check ( cx, attrs) ;
484434 }
485435
486436 fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx ImplItem < ' _ > ) {
@@ -526,3 +476,77 @@ impl EarlyLintPass for EarlyAttributes {
526476
527477 extract_msrv_attr ! ( EarlyContext ) ;
528478}
479+
480+ pub struct PostExpansionEarlyAttributes {
481+ msrv : Msrv ,
482+ }
483+
484+ impl PostExpansionEarlyAttributes {
485+ pub fn new ( conf : & ' static Conf ) -> Self {
486+ Self {
487+ msrv : conf. msrv . clone ( ) ,
488+ }
489+ }
490+ }
491+
492+ impl_lint_pass ! ( PostExpansionEarlyAttributes => [
493+ ALLOW_ATTRIBUTES ,
494+ ALLOW_ATTRIBUTES_WITHOUT_REASON ,
495+ DEPRECATED_SEMVER ,
496+ USELESS_ATTRIBUTE ,
497+ BLANKET_CLIPPY_RESTRICTION_LINTS ,
498+ SHOULD_PANIC_WITHOUT_EXPECT ,
499+ MIXED_ATTRIBUTES_STYLE ,
500+ DUPLICATED_ATTRIBUTES ,
501+ ] ) ;
502+
503+ impl EarlyLintPass for PostExpansionEarlyAttributes {
504+ fn check_crate ( & mut self , cx : & EarlyContext < ' _ > , krate : & ast:: Crate ) {
505+ blanket_clippy_restriction_lints:: check_command_line ( cx) ;
506+ duplicated_attributes:: check ( cx, & krate. attrs ) ;
507+ }
508+
509+ fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & Attribute ) {
510+ if let Some ( items) = & attr. meta_item_list ( ) {
511+ if let Some ( ident) = attr. ident ( ) {
512+ if matches ! ( ident. name, sym:: allow) && self . msrv . meets ( msrvs:: LINT_REASONS_STABILIZATION ) {
513+ allow_attributes:: check ( cx, attr) ;
514+ }
515+ if matches ! ( ident. name, sym:: allow | sym:: expect) && self . msrv . meets ( msrvs:: LINT_REASONS_STABILIZATION )
516+ {
517+ allow_attributes_without_reason:: check ( cx, ident. name , items, attr) ;
518+ }
519+ if is_lint_level ( ident. name , attr. id ) {
520+ blanket_clippy_restriction_lints:: check ( cx, ident. name , items) ;
521+ }
522+ if items. is_empty ( ) || !attr. has_name ( sym:: deprecated) {
523+ return ;
524+ }
525+ for item in items {
526+ if let MetaItemInner :: MetaItem ( mi) = & item
527+ && let MetaItemKind :: NameValue ( lit) = & mi. kind
528+ && mi. has_name ( sym:: since)
529+ {
530+ deprecated_semver:: check ( cx, item. span ( ) , lit) ;
531+ }
532+ }
533+ }
534+ }
535+
536+ if attr. has_name ( sym:: should_panic) {
537+ should_panic_without_expect:: check ( cx, attr) ;
538+ }
539+ }
540+
541+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & ' _ ast:: Item ) {
542+ match item. kind {
543+ ast:: ItemKind :: ExternCrate ( ..) | ast:: ItemKind :: Use ( ..) => useless_attribute:: check ( cx, item, & item. attrs ) ,
544+ _ => { } ,
545+ }
546+
547+ mixed_attributes_style:: check ( cx, item. span , & item. attrs ) ;
548+ duplicated_attributes:: check ( cx, & item. attrs ) ;
549+ }
550+
551+ extract_msrv_attr ! ( EarlyContext ) ;
552+ }
0 commit comments