2
2
//! to generate a clippy lint detecting said code automatically.
3
3
4
4
use crate :: utils:: get_attr;
5
- use rustc_ast:: ast:: { Attribute , LitFloatType , LitKind } ;
5
+ use rustc_ast:: ast:: { LitFloatType , LitKind } ;
6
6
use rustc_ast:: walk_list;
7
7
use rustc_data_structures:: fx:: FxHashMap ;
8
8
use rustc_hir as hir;
9
9
use rustc_hir:: intravisit:: { NestedVisitorMap , Visitor } ;
10
10
use rustc_hir:: { BindingAnnotation , Block , Expr , ExprKind , Pat , PatKind , QPath , Stmt , StmtKind , TyKind } ;
11
11
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
12
12
use rustc_middle:: hir:: map:: Map ;
13
- use rustc_session:: Session ;
14
13
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
15
14
16
15
declare_clippy_lint ! {
@@ -66,7 +65,7 @@ fn done() {
66
65
67
66
impl < ' tcx > LateLintPass < ' tcx > for Author {
68
67
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: Item < ' _ > ) {
69
- if !has_attr ( cx. sess ( ) , & item. attrs ) {
68
+ if !has_attr ( cx, item. hir_id ( ) ) {
70
69
return ;
71
70
}
72
71
prelude ( ) ;
@@ -75,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
75
74
}
76
75
77
76
fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: ImplItem < ' _ > ) {
78
- if !has_attr ( cx. sess ( ) , & item. attrs ) {
77
+ if !has_attr ( cx, item. hir_id ( ) ) {
79
78
return ;
80
79
}
81
80
prelude ( ) ;
@@ -84,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
84
83
}
85
84
86
85
fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: TraitItem < ' _ > ) {
87
- if !has_attr ( cx. sess ( ) , & item. attrs ) {
86
+ if !has_attr ( cx, item. hir_id ( ) ) {
88
87
return ;
89
88
}
90
89
prelude ( ) ;
@@ -93,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
93
92
}
94
93
95
94
fn check_variant ( & mut self , cx : & LateContext < ' tcx > , var : & ' tcx hir:: Variant < ' _ > ) {
96
- if !has_attr ( cx. sess ( ) , & var. attrs ) {
95
+ if !has_attr ( cx, var. id ) {
97
96
return ;
98
97
}
99
98
prelude ( ) ;
@@ -103,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
103
102
}
104
103
105
104
fn check_struct_field ( & mut self , cx : & LateContext < ' tcx > , field : & ' tcx hir:: StructField < ' _ > ) {
106
- if !has_attr ( cx. sess ( ) , & field. attrs ) {
105
+ if !has_attr ( cx, field. hir_id ) {
107
106
return ;
108
107
}
109
108
prelude ( ) ;
@@ -112,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
112
111
}
113
112
114
113
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
115
- if !has_attr ( cx. sess ( ) , & expr. attrs ) {
114
+ if !has_attr ( cx, expr. hir_id ) {
116
115
return ;
117
116
}
118
117
prelude ( ) ;
@@ -121,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
121
120
}
122
121
123
122
fn check_arm ( & mut self , cx : & LateContext < ' tcx > , arm : & ' tcx hir:: Arm < ' _ > ) {
124
- if !has_attr ( cx. sess ( ) , & arm. attrs ) {
123
+ if !has_attr ( cx, arm. hir_id ) {
125
124
return ;
126
125
}
127
126
prelude ( ) ;
@@ -130,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
130
129
}
131
130
132
131
fn check_stmt ( & mut self , cx : & LateContext < ' tcx > , stmt : & ' tcx hir:: Stmt < ' _ > ) {
133
- if !has_attr ( cx. sess ( ) , stmt. kind . attrs ( |id| cx . tcx . hir ( ) . item ( id ) ) ) {
132
+ if !has_attr ( cx, stmt. hir_id ) {
134
133
return ;
135
134
}
136
135
prelude ( ) ;
@@ -139,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
139
138
}
140
139
141
140
fn check_foreign_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: ForeignItem < ' _ > ) {
142
- if !has_attr ( cx. sess ( ) , & item. attrs ) {
141
+ if !has_attr ( cx, item. hir_id ( ) ) {
143
142
return ;
144
143
}
145
144
prelude ( ) ;
@@ -719,8 +718,9 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
719
718
}
720
719
}
721
720
722
- fn has_attr ( sess : & Session , attrs : & [ Attribute ] ) -> bool {
723
- get_attr ( sess, attrs, "author" ) . count ( ) > 0
721
+ fn has_attr ( cx : & LateContext < ' _ > , hir_id : hir:: HirId ) -> bool {
722
+ let attrs = cx. tcx . hir ( ) . attrs ( hir_id) ;
723
+ get_attr ( cx. sess ( ) , attrs, "author" ) . count ( ) > 0
724
724
}
725
725
726
726
#[ must_use]
0 commit comments