Skip to content

Commit f5dc5dc

Browse files
committed
Simplify clippy author.
1 parent 3137f81 commit f5dc5dc

File tree

1 file changed

+13
-13
lines changed
  • src/tools/clippy/clippy_lints/src/utils

1 file changed

+13
-13
lines changed

src/tools/clippy/clippy_lints/src/utils/author.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
//! to generate a clippy lint detecting said code automatically.
33
44
use crate::utils::get_attr;
5-
use rustc_ast::ast::{Attribute, LitFloatType, LitKind};
5+
use rustc_ast::ast::{LitFloatType, LitKind};
66
use rustc_ast::walk_list;
77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_hir as hir;
99
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
1010
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::hir::map::Map;
13-
use rustc_session::Session;
1413
use rustc_session::{declare_lint_pass, declare_tool_lint};
1514

1615
declare_clippy_lint! {
@@ -66,7 +65,7 @@ fn done() {
6665

6766
impl<'tcx> LateLintPass<'tcx> for Author {
6867
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()) {
7069
return;
7170
}
7271
prelude();
@@ -75,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
7574
}
7675

7776
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()) {
7978
return;
8079
}
8180
prelude();
@@ -84,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
8483
}
8584

8685
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()) {
8887
return;
8988
}
9089
prelude();
@@ -93,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
9392
}
9493

9594
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) {
9796
return;
9897
}
9998
prelude();
@@ -103,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
103102
}
104103

105104
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) {
107106
return;
108107
}
109108
prelude();
@@ -112,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
112111
}
113112

114113
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) {
116115
return;
117116
}
118117
prelude();
@@ -121,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
121120
}
122121

123122
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) {
125124
return;
126125
}
127126
prelude();
@@ -130,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
130129
}
131130

132131
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) {
134133
return;
135134
}
136135
prelude();
@@ -139,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
139138
}
140139

141140
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()) {
143142
return;
144143
}
145144
prelude();
@@ -719,8 +718,9 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
719718
}
720719
}
721720

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
724724
}
725725

726726
#[must_use]

0 commit comments

Comments
 (0)