Skip to content

Commit 3137f81

Browse files
committed
Access attrs directly from HirId in rustdoc::doctest.
1 parent 99ba08e commit 3137f81

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

src/librustdoc/doctest.rs

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
137137
};
138138
hir_collector.visit_testable(
139139
"".to_string(),
140-
&krate.item.attrs,
141140
CRATE_HIR_ID,
142141
krate.item.span,
143142
|this| {
@@ -991,11 +990,11 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
991990
fn visit_testable<F: FnOnce(&mut Self)>(
992991
&mut self,
993992
name: String,
994-
attrs: &[ast::Attribute],
995993
hir_id: HirId,
996994
sp: Span,
997995
nested: F,
998996
) {
997+
let attrs = self.tcx.hir().attrs(hir_id);
999998
let mut attrs = Attributes::from_ast(self.sess.diagnostic(), attrs, None);
1000999
if let Some(ref cfg) = attrs.cfg {
10011000
if !cfg.matches(&self.sess.parse_sess, Some(&self.sess.features_untracked())) {
@@ -1053,45 +1052,27 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
10531052
item.ident.to_string()
10541053
};
10551054

1056-
self.visit_testable(name, &item.attrs, item.hir_id(), item.span, |this| {
1055+
self.visit_testable(name, item.hir_id(), item.span, |this| {
10571056
intravisit::walk_item(this, item);
10581057
});
10591058
}
10601059

10611060
fn visit_trait_item(&mut self, item: &'hir hir::TraitItem<'_>) {
1062-
self.visit_testable(
1063-
item.ident.to_string(),
1064-
&item.attrs,
1065-
item.hir_id(),
1066-
item.span,
1067-
|this| {
1068-
intravisit::walk_trait_item(this, item);
1069-
},
1070-
);
1061+
self.visit_testable(item.ident.to_string(), item.hir_id(), item.span, |this| {
1062+
intravisit::walk_trait_item(this, item);
1063+
});
10711064
}
10721065

10731066
fn visit_impl_item(&mut self, item: &'hir hir::ImplItem<'_>) {
1074-
self.visit_testable(
1075-
item.ident.to_string(),
1076-
&item.attrs,
1077-
item.hir_id(),
1078-
item.span,
1079-
|this| {
1080-
intravisit::walk_impl_item(this, item);
1081-
},
1082-
);
1067+
self.visit_testable(item.ident.to_string(), item.hir_id(), item.span, |this| {
1068+
intravisit::walk_impl_item(this, item);
1069+
});
10831070
}
10841071

10851072
fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem<'_>) {
1086-
self.visit_testable(
1087-
item.ident.to_string(),
1088-
&item.attrs,
1089-
item.hir_id(),
1090-
item.span,
1091-
|this| {
1092-
intravisit::walk_foreign_item(this, item);
1093-
},
1094-
);
1073+
self.visit_testable(item.ident.to_string(), item.hir_id(), item.span, |this| {
1074+
intravisit::walk_foreign_item(this, item);
1075+
});
10951076
}
10961077

10971078
fn visit_variant(
@@ -1100,21 +1081,20 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
11001081
g: &'hir hir::Generics<'_>,
11011082
item_id: hir::HirId,
11021083
) {
1103-
self.visit_testable(v.ident.to_string(), &v.attrs, v.id, v.span, |this| {
1084+
self.visit_testable(v.ident.to_string(), v.id, v.span, |this| {
11041085
intravisit::walk_variant(this, v, g, item_id);
11051086
});
11061087
}
11071088

11081089
fn visit_struct_field(&mut self, f: &'hir hir::StructField<'_>) {
1109-
self.visit_testable(f.ident.to_string(), &f.attrs, f.hir_id, f.span, |this| {
1090+
self.visit_testable(f.ident.to_string(), f.hir_id, f.span, |this| {
11101091
intravisit::walk_struct_field(this, f);
11111092
});
11121093
}
11131094

11141095
fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef<'_>) {
11151096
self.visit_testable(
11161097
macro_def.ident.to_string(),
1117-
&macro_def.attrs,
11181098
macro_def.hir_id(),
11191099
macro_def.span,
11201100
|_| (),

0 commit comments

Comments
 (0)