Skip to content

Commit bae84a4

Browse files
committed
update rustdoc
1 parent 6c8265d commit bae84a4

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::clean::{
2222
use crate::core::DocContext;
2323
use crate::formats::item_type::ItemType;
2424

25-
type Attrs<'hir> = rustc_middle::ty::Attributes<'hir>;
25+
type Attrs<'hir> = &'hir [ast::Attribute];
2626

2727
/// Attempt to inline a definition into this AST.
2828
///
@@ -155,7 +155,7 @@ crate fn try_inline_glob(
155155
}
156156

157157
crate fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> {
158-
cx.tcx.get_attrs(did)
158+
cx.tcx.get_attrs_unchecked(did)
159159
}
160160

161161
/// Record an external fully qualified name in the external_paths cache.
@@ -691,7 +691,7 @@ crate fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
691691

692692
let trait_ = clean::TraitWithExtraInfo {
693693
trait_,
694-
is_notable: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::notable_trait),
694+
is_notable: clean::utils::has_doc_flag(cx.tcx, did, sym::notable_trait),
695695
};
696696
cx.external_traits.borrow_mut().insert(did, trait_);
697697
cx.active_extern_traits.remove(&did);

src/librustdoc/clean/types.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ impl ExternalCrate {
211211
// Failing that, see if there's an attribute specifying where to find this
212212
// external crate
213213
let did = self.crate_num.as_def_id();
214-
tcx.get_attrs(did)
215-
.lists(sym::doc)
214+
tcx.get_attrs(did, sym::doc)
215+
.flat_map(|attr| attr.meta_item_list().unwrap_or_default())
216216
.filter(|a| a.has_name(sym::html_root_url))
217217
.filter_map(|a| a.value_str())
218218
.map(to_remote)
@@ -226,11 +226,13 @@ impl ExternalCrate {
226226

227227
let as_keyword = |res: Res<!>| {
228228
if let Res::Def(DefKind::Mod, def_id) = res {
229-
let attrs = tcx.get_attrs(def_id);
230229
let mut keyword = None;
231-
for attr in attrs.lists(sym::doc) {
232-
if attr.has_name(sym::keyword) {
233-
if let Some(v) = attr.value_str() {
230+
let meta_items = tcx
231+
.get_attrs(def_id, sym::doc)
232+
.flat_map(|attr| attr.meta_item_list().unwrap_or_default());
233+
for meta in meta_items {
234+
if meta.has_name(sym::keyword) {
235+
if let Some(v) = meta.value_str() {
234236
keyword = Some(v);
235237
break;
236238
}
@@ -288,11 +290,13 @@ impl ExternalCrate {
288290
// rendering by delegating everything to a hash map.
289291
let as_primitive = |res: Res<!>| {
290292
if let Res::Def(DefKind::Mod, def_id) = res {
291-
let attrs = tcx.get_attrs(def_id);
292293
let mut prim = None;
293-
for attr in attrs.lists(sym::doc) {
294-
if let Some(v) = attr.value_str() {
295-
if attr.has_name(sym::primitive) {
294+
let meta_items = tcx
295+
.get_attrs(def_id, sym::doc)
296+
.flat_map(|attr| attr.meta_item_list().unwrap_or_default());
297+
for meta in meta_items {
298+
if let Some(v) = meta.value_str() {
299+
if meta.has_name(sym::primitive) {
296300
prim = PrimitiveType::from_symbol(v);
297301
if prim.is_some() {
298302
break;
@@ -413,7 +417,10 @@ impl Item {
413417
}
414418

415419
crate fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
416-
self.item_id.as_def_id().map(|did| tcx.get_attrs(did).inner_docs()).unwrap_or(false)
420+
self.item_id
421+
.as_def_id()
422+
.map(|did| tcx.get_attrs_unchecked(did).inner_docs())
423+
.unwrap_or(false)
417424
}
418425

419426
crate fn span(&self, tcx: TyCtxt<'_>) -> Span {
@@ -464,7 +471,7 @@ impl Item {
464471
kind: ItemKind,
465472
cx: &mut DocContext<'_>,
466473
) -> Item {
467-
let ast_attrs = cx.tcx.get_attrs(def_id);
474+
let ast_attrs = cx.tcx.get_attrs_unchecked(def_id);
468475

469476
Self::from_def_id_and_attrs_and_parts(
470477
def_id,

src/librustdoc/clean/utils.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,9 @@ crate fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<De
474474
///
475475
/// This function exists because it runs on `hir::Attributes` whereas the other is a
476476
/// `clean::Attributes` method.
477-
crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
478-
attrs.iter().any(|attr| {
479-
attr.has_name(sym::doc)
480-
&& attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))
477+
crate fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
478+
tcx.get_attrs(did, sym::doc).any(|attr| {
479+
attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))
481480
})
482481
}
483482

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
323323

324324
clean::ImportItem(ref import) => {
325325
let (stab, stab_tags) = if let Some(import_def_id) = import.source.did {
326-
let ast_attrs = cx.tcx().get_attrs(import_def_id);
326+
let ast_attrs = cx.tcx().get_attrs_unchecked(import_def_id);
327327
let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs, None));
328328

329329
// Just need an item with the correct def_id and attrs

src/librustdoc/passes/collect_trait_impls.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate
5353
while let Some(did) = parent {
5454
attr_buf.extend(
5555
cx.tcx
56-
.get_attrs(did)
57-
.iter()
58-
.filter(|attr| attr.has_name(sym::doc))
56+
.get_attrs(did, sym::doc)
5957
.filter(|attr| {
6058
if let Some([attr]) = attr.meta_item_list().as_deref() {
6159
attr.has_name(sym::cfg)

0 commit comments

Comments
 (0)