Skip to content

Commit 662f11a

Browse files
committed
Access attrs directly from HirId in rustc_lint::builtin.
1 parent 260aa9f commit 662f11a

File tree

1 file changed

+10
-38
lines changed

1 file changed

+10
-38
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,7 @@ impl MissingDoc {
508508
fn check_missing_docs_attrs(
509509
&self,
510510
cx: &LateContext<'_>,
511-
id: Option<hir::HirId>,
512-
attrs: &[ast::Attribute],
511+
id: hir::HirId,
513512
sp: Span,
514513
article: &'static str,
515514
desc: &'static str,
@@ -528,12 +527,13 @@ impl MissingDoc {
528527
// Only check publicly-visible items, using the result from the privacy pass.
529528
// It's an option so the crate root can also use this function (it doesn't
530529
// have a `NodeId`).
531-
if let Some(id) = id {
530+
if id != hir::CRATE_HIR_ID {
532531
if !cx.access_levels.is_exported(id) {
533532
return;
534533
}
535534
}
536535

536+
let attrs = cx.tcx.hir().attrs(id);
537537
let has_doc = attrs.iter().any(|a| has_doc(cx.sess(), a));
538538
if !has_doc {
539539
cx.struct_span_lint(
@@ -565,7 +565,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
565565
}
566566

567567
fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
568-
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "the", "crate");
568+
self.check_missing_docs_attrs(cx, hir::CRATE_HIR_ID, krate.item.span, "the", "crate");
569569

570570
for macro_def in krate.exported_macros {
571571
let has_doc = macro_def.attrs.iter().any(|a| has_doc(cx.sess(), a));
@@ -622,7 +622,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
622622

623623
let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
624624

625-
self.check_missing_docs_attrs(cx, Some(it.hir_id()), &it.attrs, it.span, article, desc);
625+
self.check_missing_docs_attrs(cx, it.hir_id(), it.span, article, desc);
626626
}
627627

628628
fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) {
@@ -632,14 +632,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
632632

633633
let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id());
634634

635-
self.check_missing_docs_attrs(
636-
cx,
637-
Some(trait_item.hir_id()),
638-
&trait_item.attrs,
639-
trait_item.span,
640-
article,
641-
desc,
642-
);
635+
self.check_missing_docs_attrs(cx, trait_item.hir_id(), trait_item.span, article, desc);
643636
}
644637

645638
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
@@ -649,43 +642,22 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
649642
}
650643

651644
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
652-
self.check_missing_docs_attrs(
653-
cx,
654-
Some(impl_item.hir_id()),
655-
&impl_item.attrs,
656-
impl_item.span,
657-
article,
658-
desc,
659-
);
645+
self.check_missing_docs_attrs(cx, impl_item.hir_id(), impl_item.span, article, desc);
660646
}
661647

662648
fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) {
663649
let (article, desc) = cx.tcx.article_and_description(foreign_item.def_id.to_def_id());
664-
self.check_missing_docs_attrs(
665-
cx,
666-
Some(foreign_item.hir_id()),
667-
&foreign_item.attrs,
668-
foreign_item.span,
669-
article,
670-
desc,
671-
);
650+
self.check_missing_docs_attrs(cx, foreign_item.hir_id(), foreign_item.span, article, desc);
672651
}
673652

674653
fn check_struct_field(&mut self, cx: &LateContext<'_>, sf: &hir::StructField<'_>) {
675654
if !sf.is_positional() {
676-
self.check_missing_docs_attrs(
677-
cx,
678-
Some(sf.hir_id),
679-
&sf.attrs,
680-
sf.span,
681-
"a",
682-
"struct field",
683-
)
655+
self.check_missing_docs_attrs(cx, sf.hir_id, sf.span, "a", "struct field")
684656
}
685657
}
686658

687659
fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) {
688-
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a", "variant");
660+
self.check_missing_docs_attrs(cx, v.id, v.span, "a", "variant");
689661
}
690662
}
691663

0 commit comments

Comments
 (0)