From 662f11ade6105feef7e02928e523161f1cb86940 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 00:05:29 +0100 Subject: [PATCH] Access attrs directly from HirId in rustc_lint::builtin. --- compiler/rustc_lint/src/builtin.rs | 48 +++++++----------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 4258a4b4237..2898ffc0906 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -508,8 +508,7 @@ impl MissingDoc { fn check_missing_docs_attrs( &self, cx: &LateContext<'_>, - id: Option, - attrs: &[ast::Attribute], + id: hir::HirId, sp: Span, article: &'static str, desc: &'static str, @@ -528,12 +527,13 @@ impl MissingDoc { // Only check publicly-visible items, using the result from the privacy pass. // It's an option so the crate root can also use this function (it doesn't // have a `NodeId`). - if let Some(id) = id { + if id != hir::CRATE_HIR_ID { if !cx.access_levels.is_exported(id) { return; } } + let attrs = cx.tcx.hir().attrs(id); let has_doc = attrs.iter().any(|a| has_doc(cx.sess(), a)); if !has_doc { cx.struct_span_lint( @@ -565,7 +565,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) { - self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "the", "crate"); + self.check_missing_docs_attrs(cx, hir::CRATE_HIR_ID, krate.item.span, "the", "crate"); for macro_def in krate.exported_macros { let has_doc = macro_def.attrs.iter().any(|a| has_doc(cx.sess(), a)); @@ -622,7 +622,7 @@ 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, Some(it.hir_id()), &it.attrs, it.span, article, desc); + self.check_missing_docs_attrs(cx, it.hir_id(), it.span, article, desc); } fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) { @@ -632,14 +632,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id()); - self.check_missing_docs_attrs( - cx, - Some(trait_item.hir_id()), - &trait_item.attrs, - trait_item.span, - article, - desc, - ); + self.check_missing_docs_attrs(cx, trait_item.hir_id(), trait_item.span, article, desc); } fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { @@ -649,43 +642,22 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); - self.check_missing_docs_attrs( - cx, - Some(impl_item.hir_id()), - &impl_item.attrs, - impl_item.span, - article, - desc, - ); + self.check_missing_docs_attrs(cx, impl_item.hir_id(), impl_item.span, article, desc); } fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) { let (article, desc) = cx.tcx.article_and_description(foreign_item.def_id.to_def_id()); - self.check_missing_docs_attrs( - cx, - Some(foreign_item.hir_id()), - &foreign_item.attrs, - foreign_item.span, - article, - desc, - ); + self.check_missing_docs_attrs(cx, foreign_item.hir_id(), foreign_item.span, article, desc); } fn check_struct_field(&mut self, cx: &LateContext<'_>, sf: &hir::StructField<'_>) { if !sf.is_positional() { - self.check_missing_docs_attrs( - cx, - Some(sf.hir_id), - &sf.attrs, - sf.span, - "a", - "struct field", - ) + self.check_missing_docs_attrs(cx, sf.hir_id, sf.span, "a", "struct field") } } fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) { - self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a", "variant"); + self.check_missing_docs_attrs(cx, v.id, v.span, "a", "variant"); } }