mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Remove hir::Item::attrs.
This commit is contained in:
parent
49835d8abf
commit
dc9560cfd2
11 changed files with 25 additions and 16 deletions
|
@ -276,14 +276,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
if is_relevant_item(cx, item) {
|
if is_relevant_item(cx, item) {
|
||||||
check_attrs(cx, item.span, item.ident.name, &item.attrs)
|
check_attrs(cx, item.span, item.ident.name, attrs)
|
||||||
}
|
}
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
|
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
|
||||||
let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym::macro_use));
|
let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use));
|
||||||
|
|
||||||
for attr in item.attrs {
|
for attr in attrs {
|
||||||
if in_external_macro(cx.sess(), attr.span) {
|
if in_external_macro(cx.sess(), attr.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,8 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
|
||||||
}) = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
let ty = cx.tcx.type_of(item.def_id);
|
let ty = cx.tcx.type_of(item.def_id);
|
||||||
let is_automatically_derived = is_automatically_derived(&*item.attrs);
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
|
let is_automatically_derived = is_automatically_derived(attrs);
|
||||||
|
|
||||||
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
|
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
|
||||||
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);
|
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);
|
||||||
|
|
|
@ -214,7 +214,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||||
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
|
let headers = check_attrs(cx, &self.valid_idents, attrs);
|
||||||
match item.kind {
|
match item.kind {
|
||||||
hir::ItemKind::Fn(ref sig, _, body_id) => {
|
hir::ItemKind::Fn(ref sig, _, body_id) => {
|
||||||
if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
|
if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
|
||||||
|
|
|
@ -73,7 +73,8 @@ impl LateLintPass<'_> for ExhaustiveItems {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
|
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
|
||||||
if cx.access_levels.is_exported(item.hir_id());
|
if cx.access_levels.is_exported(item.hir_id());
|
||||||
if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
|
if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
|
||||||
then {
|
then {
|
||||||
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {
|
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {
|
||||||
if v.fields().iter().any(|f| !f.vis.node.is_pub()) {
|
if v.fields().iter().any(|f| !f.vis.node.is_pub()) {
|
||||||
|
|
|
@ -280,7 +280,8 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||||
let attr = must_use_attr(&item.attrs);
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
|
let attr = must_use_attr(attrs);
|
||||||
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
|
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
|
||||||
let is_public = cx.access_levels.is_exported(item.hir_id());
|
let is_public = cx.access_levels.is_exported(item.hir_id());
|
||||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||||
|
@ -291,7 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
|
||||||
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
|
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() {
|
if is_public && !is_proc_macro(cx.sess(), attrs) && attr_by_name(attrs, "no_mangle").is_none() {
|
||||||
check_must_use_candidate(
|
check_must_use_candidate(
|
||||||
cx,
|
cx,
|
||||||
&sig.decl,
|
&sig.decl,
|
||||||
|
|
|
@ -107,8 +107,8 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if cx.sess().opts.edition >= Edition::Edition2018;
|
if cx.sess().opts.edition >= Edition::Edition2018;
|
||||||
if let hir::ItemKind::Use(path, _kind) = &item.kind;
|
if let hir::ItemKind::Use(path, _kind) = &item.kind;
|
||||||
if let Some(mac_attr) = item
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
.attrs
|
if let Some(mac_attr) = attrs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
|
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
|
||||||
if let Res::Def(DefKind::Mod, id) = path.res;
|
if let Res::Def(DefKind::Mod, id) = path.res;
|
||||||
|
|
|
@ -161,7 +161,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||||
|
|
||||||
let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
|
let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
|
||||||
|
|
||||||
self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc);
|
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||||
|
self.check_missing_docs_attrs(cx, attrs, it.span, article, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
|
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
|
||||||
|
|
|
@ -93,7 +93,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||||
match it.kind {
|
match it.kind {
|
||||||
hir::ItemKind::Fn(..) => {
|
hir::ItemKind::Fn(..) => {
|
||||||
let desc = "a function";
|
let desc = "a function";
|
||||||
check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
|
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||||
|
check_missing_inline_attrs(cx, attrs, it.span, desc);
|
||||||
},
|
},
|
||||||
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, trait_items) => {
|
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, trait_items) => {
|
||||||
// note: we need to check if the trait is exported so we can't use
|
// note: we need to check if the trait is exported so we can't use
|
||||||
|
|
|
@ -115,8 +115,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if is_automatically_derived(item.attrs) {
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
|
if is_automatically_derived(attrs) {
|
||||||
debug_assert!(self.derived_item.is_none());
|
debug_assert!(self.derived_item.is_none());
|
||||||
self.derived_item = Some(item.def_id);
|
self.derived_item = Some(item.def_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind;
|
if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind;
|
||||||
if !is_automatically_derived(&*item.attrs);
|
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||||
|
if !is_automatically_derived(attrs);
|
||||||
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
|
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
|
||||||
if trait_ref.path.res.def_id() == eq_trait;
|
if trait_ref.path.res.def_id() == eq_trait;
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -33,7 +33,7 @@ declare_lint_pass!(DeepCodeInspector => [DEEP_CODE_INSPECTION]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||||
if !has_attr(cx.sess(), &item.attrs) {
|
if !has_attr(cx.sess(), cx.tcx.hir().attrs(item.hir_id())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print_item(cx, item);
|
print_item(cx, item);
|
||||||
|
|
Loading…
Reference in a new issue