@@ -14,8 +14,8 @@ mod utils;
14
14
15
15
use clippy_config:: Conf ;
16
16
use clippy_config:: msrvs:: { self , Msrv } ;
17
- use rustc_ast:: { Attribute , MetaItemInner , MetaItemKind } ;
18
- use rustc_hir:: { ImplItem , Item , ItemKind , TraitItem } ;
17
+ use rustc_ast:: { Attribute , MetaItemInner , MetaItemKind , self as ast } ;
18
+ use rustc_hir:: { ImplItem , Item , TraitItem } ;
19
19
use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass } ;
20
20
use rustc_session:: impl_lint_pass;
21
21
use rustc_span:: sym;
@@ -417,12 +417,6 @@ impl_lint_pass!(Attributes => [
417
417
ALLOW_ATTRIBUTES ,
418
418
ALLOW_ATTRIBUTES_WITHOUT_REASON ,
419
419
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 ,
426
420
] ) ;
427
421
428
422
impl Attributes {
@@ -434,53 +428,11 @@ impl Attributes {
434
428
}
435
429
436
430
impl < ' 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
-
473
431
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' _ > ) {
474
432
let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
475
433
if is_relevant_item ( cx, item) {
476
434
inline_always:: check ( cx, item. span , item. ident . name , attrs) ;
477
435
}
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) ;
484
436
}
485
437
486
438
fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx ImplItem < ' _ > ) {
@@ -526,3 +478,77 @@ impl EarlyLintPass for EarlyAttributes {
526
478
527
479
extract_msrv_attr ! ( EarlyContext ) ;
528
480
}
481
+
482
+ pub struct PostExpansionEarlyAttributes {
483
+ msrv : Msrv ,
484
+ }
485
+
486
+ impl PostExpansionEarlyAttributes {
487
+ pub fn new ( conf : & ' static Conf ) -> Self {
488
+ Self {
489
+ msrv : conf. msrv . clone ( ) ,
490
+ }
491
+ }
492
+ }
493
+
494
+ impl_lint_pass ! ( PostExpansionEarlyAttributes => [
495
+ ALLOW_ATTRIBUTES ,
496
+ ALLOW_ATTRIBUTES_WITHOUT_REASON ,
497
+ DEPRECATED_SEMVER ,
498
+ USELESS_ATTRIBUTE ,
499
+ BLANKET_CLIPPY_RESTRICTION_LINTS ,
500
+ SHOULD_PANIC_WITHOUT_EXPECT ,
501
+ MIXED_ATTRIBUTES_STYLE ,
502
+ DUPLICATED_ATTRIBUTES ,
503
+ ] ) ;
504
+
505
+ impl EarlyLintPass for PostExpansionEarlyAttributes {
506
+ fn check_crate ( & mut self , cx : & EarlyContext < ' _ > , krate : & ast:: Crate ) {
507
+ blanket_clippy_restriction_lints:: check_command_line ( cx) ;
508
+ duplicated_attributes:: check ( cx, & krate. attrs ) ;
509
+ }
510
+
511
+ fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & Attribute ) {
512
+ if let Some ( items) = & attr. meta_item_list ( ) {
513
+ if let Some ( ident) = attr. ident ( ) {
514
+ if matches ! ( ident. name, sym:: allow) && self . msrv . meets ( msrvs:: LINT_REASONS_STABILIZATION ) {
515
+ allow_attributes:: check ( cx, attr) ;
516
+ }
517
+ if matches ! ( ident. name, sym:: allow | sym:: expect) && self . msrv . meets ( msrvs:: LINT_REASONS_STABILIZATION )
518
+ {
519
+ allow_attributes_without_reason:: check ( cx, ident. name , items, attr) ;
520
+ }
521
+ if is_lint_level ( ident. name , attr. id ) {
522
+ blanket_clippy_restriction_lints:: check ( cx, ident. name , items) ;
523
+ }
524
+ if items. is_empty ( ) || !attr. has_name ( sym:: deprecated) {
525
+ return ;
526
+ }
527
+ for item in items {
528
+ if let MetaItemInner :: MetaItem ( mi) = & item
529
+ && let MetaItemKind :: NameValue ( lit) = & mi. kind
530
+ && mi. has_name ( sym:: since)
531
+ {
532
+ deprecated_semver:: check ( cx, item. span ( ) , lit) ;
533
+ }
534
+ }
535
+ }
536
+ }
537
+
538
+ if attr. has_name ( sym:: should_panic) {
539
+ should_panic_without_expect:: check ( cx, attr) ;
540
+ }
541
+ }
542
+
543
+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & ' _ ast:: Item ) {
544
+ match item. kind {
545
+ ast:: ItemKind :: ExternCrate ( ..) | ast:: ItemKind :: Use ( ..) => useless_attribute:: check ( cx, item, & item. attrs ) ,
546
+ _ => { } ,
547
+ }
548
+
549
+ mixed_attributes_style:: check ( cx, item. span , & item. attrs ) ;
550
+ duplicated_attributes:: check ( cx, & item. attrs ) ;
551
+ }
552
+
553
+ extract_msrv_attr ! ( EarlyContext ) ;
554
+ }
0 commit comments