Remove hir::Item::attrs.
This commit is contained in:
parent
5474f17011
commit
c701872a6c
32 changed files with 104 additions and 76 deletions
|
|
@ -863,7 +863,8 @@ fn clean_fn_or_proc_macro(
|
|||
name: &mut Symbol,
|
||||
cx: &mut DocContext<'_>,
|
||||
) -> ItemKind {
|
||||
let macro_kind = item.attrs.iter().find_map(|a| {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let macro_kind = attrs.iter().find_map(|a| {
|
||||
if a.has_name(sym::proc_macro) {
|
||||
Some(MacroKind::Bang)
|
||||
} else if a.has_name(sym::proc_macro_derive) {
|
||||
|
|
@ -877,8 +878,7 @@ fn clean_fn_or_proc_macro(
|
|||
match macro_kind {
|
||||
Some(kind) => {
|
||||
if kind == MacroKind::Derive {
|
||||
*name = item
|
||||
.attrs
|
||||
*name = attrs
|
||||
.lists(sym::proc_macro_derive)
|
||||
.find_map(|mi| mi.ident())
|
||||
.expect("proc-macro derives require a name")
|
||||
|
|
@ -886,7 +886,7 @@ fn clean_fn_or_proc_macro(
|
|||
}
|
||||
|
||||
let mut helpers = Vec::new();
|
||||
for mi in item.attrs.lists(sym::proc_macro_derive) {
|
||||
for mi in attrs.lists(sym::proc_macro_derive) {
|
||||
if !mi.has_name(sym::attributes) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -2102,8 +2102,9 @@ fn clean_extern_crate(
|
|||
let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id).unwrap_or(LOCAL_CRATE);
|
||||
// this is the ID of the crate itself
|
||||
let crate_def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
|
||||
let attrs = cx.tcx.hir().attrs(krate.hir_id());
|
||||
let please_inline = krate.vis.node.is_pub()
|
||||
&& krate.attrs.iter().any(|a| {
|
||||
&& attrs.iter().any(|a| {
|
||||
a.has_name(sym::doc)
|
||||
&& match a.meta_item_list() {
|
||||
Some(l) => attr::list_contains_name(&l, sym::inline),
|
||||
|
|
@ -2121,7 +2122,7 @@ fn clean_extern_crate(
|
|||
cx.tcx.parent_module(krate.hir_id()).to_def_id(),
|
||||
res,
|
||||
name,
|
||||
Some(krate.attrs),
|
||||
Some(attrs),
|
||||
&mut visited,
|
||||
) {
|
||||
return items;
|
||||
|
|
@ -2130,7 +2131,7 @@ fn clean_extern_crate(
|
|||
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
|
||||
vec![Item {
|
||||
name: Some(name),
|
||||
attrs: box krate.attrs.clean(cx),
|
||||
attrs: box attrs.clean(cx),
|
||||
source: krate.span.clean(cx),
|
||||
def_id: crate_def_id,
|
||||
visibility: krate.vis.clean(cx),
|
||||
|
|
@ -2152,7 +2153,8 @@ fn clean_use_statement(
|
|||
return Vec::new();
|
||||
}
|
||||
|
||||
let inline_attr = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
|
||||
let attrs = cx.tcx.hir().attrs(import.hir_id());
|
||||
let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline);
|
||||
let pub_underscore = import.vis.node.is_pub() && name == kw::Underscore;
|
||||
|
||||
if pub_underscore {
|
||||
|
|
@ -2174,7 +2176,7 @@ fn clean_use_statement(
|
|||
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
|
||||
let mut denied = !import.vis.node.is_pub()
|
||||
|| pub_underscore
|
||||
|| import.attrs.iter().any(|a| {
|
||||
|| attrs.iter().any(|a| {
|
||||
a.has_name(sym::doc)
|
||||
&& match a.meta_item_list() {
|
||||
Some(l) => {
|
||||
|
|
@ -2214,7 +2216,7 @@ fn clean_use_statement(
|
|||
cx.tcx.parent_module(import.hir_id()).to_def_id(),
|
||||
path.res,
|
||||
name,
|
||||
Some(import.attrs),
|
||||
Some(attrs),
|
||||
&mut visited,
|
||||
) {
|
||||
items.push(Item::from_def_id_and_parts(
|
||||
|
|
|
|||
|
|
@ -285,10 +285,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
let attrs = self.cx.tcx.hir().attrs(item.hir_id());
|
||||
|
||||
// If there was a private module in the current path then don't bother inlining
|
||||
// anything as it will probably be stripped anyway.
|
||||
if item.vis.node.is_pub() && self.inside_public_path {
|
||||
let please_inline = item.attrs.iter().any(|item| match item.meta_item_list() {
|
||||
let please_inline = attrs.iter().any(|item| match item.meta_item_list() {
|
||||
Some(ref list) if item.has_name(sym::doc) => {
|
||||
list.iter().any(|i| i.has_name(sym::inline))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,14 +276,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
|||
}
|
||||
|
||||
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) {
|
||||
check_attrs(cx, item.span, item.ident.name, &item.attrs)
|
||||
check_attrs(cx, item.span, item.ident.name, attrs)
|
||||
}
|
||||
match item.kind {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,8 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
|
|||
}) = item.kind
|
||||
{
|
||||
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_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<'_>) {
|
||||
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 {
|
||||
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)) {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ impl LateLintPass<'_> for ExhaustiveItems {
|
|||
if_chain! {
|
||||
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
|
||||
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 {
|
||||
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {
|
||||
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<'_>) {
|
||||
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 {
|
||||
let is_public = cx.access_levels.is_exported(item.hir_id());
|
||||
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);
|
||||
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(
|
||||
cx,
|
||||
&sig.decl,
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
|
|||
if_chain! {
|
||||
if cx.sess().opts.edition >= Edition::Edition2018;
|
||||
if let hir::ItemKind::Use(path, _kind) = &item.kind;
|
||||
if let Some(mac_attr) = item
|
||||
.attrs
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
if let Some(mac_attr) = attrs
|
||||
.iter()
|
||||
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
|
||||
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());
|
||||
|
||||
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<'_>) {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
|||
match it.kind {
|
||||
hir::ItemKind::Fn(..) => {
|
||||
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) => {
|
||||
// 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<'_>) {
|
||||
if is_automatically_derived(item.attrs) {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
if is_automatically_derived(attrs) {
|
||||
debug_assert!(self.derived_item.is_none());
|
||||
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<'_>) {
|
||||
if_chain! {
|
||||
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 trait_ref.path.res.def_id() == eq_trait;
|
||||
then {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ declare_lint_pass!(DeepCodeInspector => [DEEP_CODE_INSPECTION]);
|
|||
|
||||
impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
||||
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;
|
||||
}
|
||||
print_item(cx, item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue