mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 03:03:21 +00:00
Remove hir::Item::attrs.
This commit is contained in:
parent
5474f17011
commit
c701872a6c
@ -242,7 +242,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let hir_id = self.lower_node_id(i.id);
|
||||
let attrs = self.lower_attrs(hir_id, &i.attrs);
|
||||
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
|
||||
Some(hir::Item { def_id: hir_id.expect_owner(), ident, attrs, kind, vis, span: i.span })
|
||||
Some(hir::Item { def_id: hir_id.expect_owner(), ident, kind, vis, span: i.span })
|
||||
}
|
||||
|
||||
fn lower_item_kind(
|
||||
@ -556,7 +556,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
this.insert_item(hir::Item {
|
||||
def_id: new_id.expect_owner(),
|
||||
ident,
|
||||
attrs,
|
||||
kind,
|
||||
vis,
|
||||
span,
|
||||
@ -629,7 +628,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
this.insert_item(hir::Item {
|
||||
def_id: new_hir_id.expect_owner(),
|
||||
ident,
|
||||
attrs,
|
||||
kind,
|
||||
vis,
|
||||
span: use_tree.span,
|
||||
|
@ -1579,7 +1579,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
let opaque_ty_item = hir::Item {
|
||||
def_id: opaque_ty_id,
|
||||
ident: Ident::invalid(),
|
||||
attrs: Default::default(),
|
||||
kind: opaque_ty_item_kind,
|
||||
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
|
||||
span: opaque_ty_span,
|
||||
|
@ -2697,7 +2697,6 @@ impl ItemId {
|
||||
pub struct Item<'hir> {
|
||||
pub ident: Ident,
|
||||
pub def_id: LocalDefId,
|
||||
pub attrs: &'hir [Attribute],
|
||||
pub kind: ItemKind<'hir>,
|
||||
pub vis: Visibility<'hir>,
|
||||
pub span: Span,
|
||||
@ -3077,7 +3076,7 @@ mod size_asserts {
|
||||
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
|
||||
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
|
||||
|
||||
rustc_data_structures::static_assert_size!(super::Item<'static>, 200);
|
||||
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
|
||||
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
|
||||
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 152);
|
||||
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136);
|
||||
|
@ -181,11 +181,10 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItem<'_> {
|
||||
|
||||
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
|
||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||
let Item { ident, ref attrs, def_id: _, ref kind, ref vis, span } = *self;
|
||||
let Item { ident, def_id: _, ref kind, ref vis, span } = *self;
|
||||
|
||||
hcx.hash_hir_item_like(|hcx| {
|
||||
ident.name.hash_stable(hcx, hasher);
|
||||
attrs.hash_stable(hcx, hasher);
|
||||
kind.hash_stable(hcx, hasher);
|
||||
vis.hash_stable(hcx, hasher);
|
||||
span.hash_stable(hcx, hasher);
|
||||
|
@ -561,7 +561,8 @@ impl<'a> State<'a> {
|
||||
pub fn print_item(&mut self, item: &hir::Item<'_>) {
|
||||
self.hardbreak_if_not_bol();
|
||||
self.maybe_print_comment(item.span.lo());
|
||||
self.print_outer_attributes(&item.attrs);
|
||||
let attrs = self.attrs(item.hir_id());
|
||||
self.print_outer_attributes(attrs);
|
||||
self.ann.pre(self, AnnNode::Item(item));
|
||||
match item.kind {
|
||||
hir::ItemKind::ExternCrate(orig_name) => {
|
||||
@ -646,14 +647,14 @@ impl<'a> State<'a> {
|
||||
self.print_ident(item.ident);
|
||||
self.nbsp();
|
||||
self.bopen();
|
||||
self.print_mod(_mod, &item.attrs);
|
||||
self.print_mod(_mod, attrs);
|
||||
self.bclose(item.span);
|
||||
}
|
||||
hir::ItemKind::ForeignMod { abi, items } => {
|
||||
self.head("extern");
|
||||
self.word_nbsp(abi.to_string());
|
||||
self.bopen();
|
||||
self.print_inner_attributes(item.attrs);
|
||||
self.print_inner_attributes(self.attrs(item.hir_id()));
|
||||
for item in items {
|
||||
self.ann.nested(self, Nested::ForeignItem(item.id));
|
||||
}
|
||||
@ -737,7 +738,7 @@ impl<'a> State<'a> {
|
||||
|
||||
self.s.space();
|
||||
self.bopen();
|
||||
self.print_inner_attributes(&item.attrs);
|
||||
self.print_inner_attributes(attrs);
|
||||
for impl_item in items {
|
||||
self.ann.nested(self, Nested::ImplItem(impl_item.id));
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ struct Finder<'tcx> {
|
||||
|
||||
impl<'v> ItemLikeVisitor<'v> for Finder<'_> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
if self.tcx.sess.contains_name(&item.attrs, sym::rustc_proc_macro_decls) {
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
if self.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
|
||||
self.decls = Some(item.hir_id());
|
||||
}
|
||||
}
|
||||
|
@ -1092,9 +1092,10 @@ declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS, NO_MANGLE_GEN
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||
match it.kind {
|
||||
hir::ItemKind::Fn(.., ref generics, _) => {
|
||||
if let Some(no_mangle_attr) = cx.sess().find_by_name(&it.attrs, sym::no_mangle) {
|
||||
if let Some(no_mangle_attr) = cx.sess().find_by_name(attrs, sym::no_mangle) {
|
||||
for param in generics.params {
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {}
|
||||
@ -1120,7 +1121,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Const(..) => {
|
||||
if cx.sess().contains_name(&it.attrs, sym::no_mangle) {
|
||||
if cx.sess().contains_name(attrs, sym::no_mangle) {
|
||||
// Const items do not refer to a particular location in memory, and therefore
|
||||
// don't have anything to attach a symbol to
|
||||
cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, |lint| {
|
||||
@ -1800,7 +1801,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::rustc_test_marker) {
|
||||
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||
if let Some(attr) = cx.sess().find_by_name(attrs, sym::rustc_test_marker) {
|
||||
cx.struct_span_lint(UNNAMEABLE_TEST_ITEMS, attr.span, |lint| {
|
||||
lint.build("cannot test inner items").emit()
|
||||
});
|
||||
|
@ -283,7 +283,7 @@ fn is_doc_keyword(s: Symbol) -> bool {
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
|
||||
for attr in item.attrs {
|
||||
for attr in cx.tcx.hir().attrs(item.hir_id()) {
|
||||
if !attr.has_name(sym::doc) {
|
||||
continue;
|
||||
}
|
||||
|
@ -505,8 +505,9 @@ impl NonUpperCaseGlobals {
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||
match it.kind {
|
||||
hir::ItemKind::Static(..) if !cx.sess().contains_name(&it.attrs, sym::no_mangle) => {
|
||||
hir::ItemKind::Static(..) if !cx.sess().contains_name(attrs, sym::no_mangle) => {
|
||||
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident);
|
||||
}
|
||||
hir::ItemKind::Const(..) => {
|
||||
|
@ -36,7 +36,9 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
||||
|
||||
// First, add all of the custom #[link_args] attributes
|
||||
let sess = &self.tcx.sess;
|
||||
for m in it.attrs.iter().filter(|a| sess.check_name(a, sym::link_args)) {
|
||||
for m in
|
||||
self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| sess.check_name(a, sym::link_args))
|
||||
{
|
||||
if let Some(linkarg) = m.value_str() {
|
||||
self.add_link_args(linkarg);
|
||||
}
|
||||
|
@ -44,7 +44,8 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
||||
|
||||
// Process all of the #[link(..)]-style arguments
|
||||
let sess = &self.tcx.sess;
|
||||
for m in it.attrs.iter().filter(|a| sess.check_name(a, sym::link)) {
|
||||
for m in self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| sess.check_name(a, sym::link))
|
||||
{
|
||||
let items = match m.meta_item_list() {
|
||||
Some(item) => item,
|
||||
None => continue,
|
||||
|
@ -80,10 +80,11 @@ fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)
|
||||
|
||||
// Beware, this is duplicated in `librustc_builtin_macros/test_harness.rs`
|
||||
// (with `ast::Item`), so make sure to keep them in sync.
|
||||
fn entry_point_type(sess: &Session, item: &Item<'_>, at_root: bool) -> EntryPointType {
|
||||
if sess.contains_name(&item.attrs, sym::start) {
|
||||
fn entry_point_type(ctxt: &EntryContext<'_, '_>, item: &Item<'_>, at_root: bool) -> EntryPointType {
|
||||
let attrs = ctxt.map.attrs(item.hir_id());
|
||||
if ctxt.session.contains_name(attrs, sym::start) {
|
||||
EntryPointType::Start
|
||||
} else if sess.contains_name(&item.attrs, sym::main) {
|
||||
} else if ctxt.session.contains_name(attrs, sym::main) {
|
||||
EntryPointType::MainAttr
|
||||
} else if item.ident.name == sym::main {
|
||||
if at_root {
|
||||
@ -103,13 +104,14 @@ fn throw_attr_err(sess: &Session, span: Span, attr: &str) {
|
||||
}
|
||||
|
||||
fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
|
||||
match entry_point_type(&ctxt.session, item, at_root) {
|
||||
match entry_point_type(ctxt, item, at_root) {
|
||||
EntryPointType::None => (),
|
||||
_ if !matches!(item.kind, ItemKind::Fn(..)) => {
|
||||
if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::start) {
|
||||
let attrs = ctxt.map.attrs(item.hir_id());
|
||||
if let Some(attr) = ctxt.session.find_by_name(attrs, sym::start) {
|
||||
throw_attr_err(&ctxt.session, attr.span, "start");
|
||||
}
|
||||
if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::main) {
|
||||
if let Some(attr) = ctxt.session.find_by_name(attrs, sym::main) {
|
||||
throw_attr_err(&ctxt.session, attr.span, "main");
|
||||
}
|
||||
}
|
||||
|
@ -751,8 +751,9 @@ impl Visitor<'tcx> for Checker<'tcx> {
|
||||
// error if all involved types and traits are stable, because
|
||||
// it will have no effect.
|
||||
// See: https://github.com/rust-lang/rust/issues/55436
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
if let (Some((Stability { level: attr::Unstable { .. }, .. }, span)), _) =
|
||||
attr::find_stability(&self.tcx.sess, &item.attrs, item.span)
|
||||
attr::find_stability(&self.tcx.sess, attrs, item.span)
|
||||
{
|
||||
let mut c = CheckTraitImplStable { tcx: self.tcx, fully_stable: true };
|
||||
c.visit_ty(self_ty);
|
||||
|
@ -16,7 +16,8 @@ struct RegistrarFinder<'tcx> {
|
||||
impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
if let hir::ItemKind::Fn(..) = item.kind {
|
||||
if self.tcx.sess.contains_name(&item.attrs, sym::plugin_registrar) {
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
if self.tcx.sess.contains_name(attrs, sym::plugin_registrar) {
|
||||
self.registrars.push((item.def_id, item.span));
|
||||
}
|
||||
}
|
||||
|
@ -1239,7 +1239,8 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap<Vec<ObjectLifet
|
||||
let result = object_lifetime_defaults_for_item(tcx, generics);
|
||||
|
||||
// Debugging aid.
|
||||
if tcx.sess.contains_name(&item.attrs, sym::rustc_object_lifetime_default) {
|
||||
let attrs = tcx.hir().attrs(item.hir_id());
|
||||
if tcx.sess.contains_name(attrs, sym::rustc_object_lifetime_default) {
|
||||
let object_lifetime_default_reprs: String = result
|
||||
.iter()
|
||||
.map(|set| match *set {
|
||||
|
@ -496,6 +496,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
|
||||
if !self.span.filter_generated(item.ident.span) {
|
||||
let span = self.span_from_span(item.ident.span);
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
self.dumper.dump_def(
|
||||
&access_from!(self.save_ctxt, item, item.hir_id()),
|
||||
Def {
|
||||
@ -508,9 +509,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
parent: None,
|
||||
children: fields,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), &self.save_ctxt),
|
||||
attributes: lower_attributes(attrs.to_vec(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -671,6 +672,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
let span = self.span_from_span(item.ident.span);
|
||||
let children =
|
||||
methods.iter().map(|i| id_from_def_id(i.id.def_id.to_def_id())).collect();
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
self.dumper.dump_def(
|
||||
&access_from!(self.save_ctxt, item, item.hir_id()),
|
||||
Def {
|
||||
@ -683,9 +685,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
parent: None,
|
||||
children,
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), &self.save_ctxt),
|
||||
attributes: lower_attributes(attrs.to_vec(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -1260,6 +1262,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
|
||||
if !self.span.filter_generated(item.ident.span) {
|
||||
let span = self.span_from_span(item.ident.span);
|
||||
let id = id_from_def_id(item.def_id.to_def_id());
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access_from!(self.save_ctxt, item, item.hir_id()),
|
||||
@ -1273,9 +1276,9 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, &self.save_ctxt),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), &self.save_ctxt),
|
||||
attributes: lower_attributes(attrs.to_vec(), &self.save_ctxt),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -203,6 +203,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
|
||||
pub fn get_item_data(&self, item: &hir::Item<'_>) -> Option<Data> {
|
||||
let def_id = item.def_id.to_def_id();
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
match item.kind {
|
||||
hir::ItemKind::Fn(ref sig, ref generics, _) => {
|
||||
let qualname = format!("::{}", self.tcx.def_path_str(def_id));
|
||||
@ -225,9 +226,9 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(&item.attrs),
|
||||
docs: self.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), self),
|
||||
attributes: lower_attributes(attrs.to_vec(), self),
|
||||
}))
|
||||
}
|
||||
hir::ItemKind::Static(ref typ, ..) => {
|
||||
@ -248,9 +249,9 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(&item.attrs),
|
||||
docs: self.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), self),
|
||||
attributes: lower_attributes(attrs.to_vec(), self),
|
||||
}))
|
||||
}
|
||||
hir::ItemKind::Const(ref typ, _) => {
|
||||
@ -270,9 +271,9 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
parent: None,
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(&item.attrs),
|
||||
docs: self.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), self),
|
||||
attributes: lower_attributes(attrs.to_vec(), self),
|
||||
}))
|
||||
}
|
||||
hir::ItemKind::Mod(ref m) => {
|
||||
@ -297,9 +298,9 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
.map(|i| id_from_def_id(i.def_id.to_def_id()))
|
||||
.collect(),
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(&item.attrs),
|
||||
docs: self.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), self),
|
||||
attributes: lower_attributes(attrs.to_vec(), self),
|
||||
}))
|
||||
}
|
||||
hir::ItemKind::Enum(ref def, ref generics) => {
|
||||
@ -318,9 +319,9 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
parent: None,
|
||||
children: def.variants.iter().map(|v| id_from_hir_id(v.id, self)).collect(),
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(&item.attrs),
|
||||
docs: self.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
attributes: lower_attributes(item.attrs.to_vec(), self),
|
||||
attributes: lower_attributes(attrs.to_vec(), self),
|
||||
}))
|
||||
}
|
||||
hir::ItemKind::Impl(hir::Impl { ref of_trait, ref self_ty, ref items, .. }) => {
|
||||
|
@ -1466,11 +1466,12 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
|
||||
if self.span.map_or(true, |span| item.span < span) {
|
||||
if !item.span.from_expansion() {
|
||||
// Don't insert between attributes and an item.
|
||||
if item.attrs.is_empty() {
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
if attrs.is_empty() {
|
||||
self.span = Some(item.span.shrink_to_lo());
|
||||
} else {
|
||||
// Find the first attribute on the item.
|
||||
for attr in item.attrs {
|
||||
for attr in attrs {
|
||||
if self.span.map_or(true, |span| attr.span < span) {
|
||||
self.span = Some(attr.span.shrink_to_lo());
|
||||
}
|
||||
|
@ -201,7 +201,8 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
for attr in it.attrs {
|
||||
let attrs = tcx.hir().attrs(main_id);
|
||||
for attr in attrs {
|
||||
if tcx.sess.check_name(attr, sym::track_caller) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
@ -300,7 +301,8 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
for attr in it.attrs {
|
||||
let attrs = tcx.hir().attrs(start_id);
|
||||
for attr in attrs {
|
||||
if tcx.sess.check_name(attr, sym::track_caller) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
|
@ -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…
Reference in New Issue
Block a user