Skip to content

Commit 21fb3ce

Browse files
committed
Auto merge of #31967 - mitaa:rdoc-refactor, r=alexcrichton
This is mostly cleanup of individual code bits and code reuse for `clean::Attribute` handling. The only change in behaviour should be that emitted sources are now being recorded and queried when trying to create src-links to local source-files. r? @alexcrichton
2 parents 8484831 + 938c8c1 commit 21fb3ce

File tree

8 files changed

+356
-542
lines changed

8 files changed

+356
-542
lines changed

src/librustdoc/clean/inline.rs

+12-33
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc::middle::const_eval;
2626

2727
use core::DocContext;
2828
use doctree;
29-
use clean;
29+
use clean::{self, Attributes};
3030

3131
use super::{Clean, ToSource};
3232

@@ -138,13 +138,10 @@ pub fn load_attrs(cx: &DocContext, tcx: &TyCtxt,
138138
/// These names are used later on by HTML rendering to generate things like
139139
/// source links back to the original item.
140140
pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
141-
match cx.tcx_opt() {
142-
Some(tcx) => {
143-
let fqn = tcx.sess.cstore.extern_item_path(did);
144-
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
145-
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
146-
}
147-
None => {}
141+
if let Some(tcx) = cx.tcx_opt() {
142+
let fqn = tcx.sess.cstore.extern_item_path(did);
143+
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
144+
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
148145
}
149146
}
150147

@@ -230,12 +227,9 @@ pub fn build_impls(cx: &DocContext, tcx: &TyCtxt,
230227
tcx.populate_inherent_implementations_for_type_if_necessary(did);
231228
let mut impls = Vec::new();
232229

233-
match tcx.inherent_impls.borrow().get(&did) {
234-
None => {}
235-
Some(i) => {
236-
for &did in i.iter() {
237-
build_impl(cx, tcx, did, &mut impls);
238-
}
230+
if let Some(i) = tcx.inherent_impls.borrow().get(&did) {
231+
for &did in i.iter() {
232+
build_impl(cx, tcx, did, &mut impls);
239233
}
240234
}
241235

@@ -259,7 +253,7 @@ pub fn build_impls(cx: &DocContext, tcx: &TyCtxt,
259253
cstore::DlImpl(did) => build_impl(cx, tcx, did, impls),
260254
cstore::DlDef(Def::Mod(did)) => {
261255
// Don't recurse if this is a #[doc(hidden)] module
262-
if load_attrs(cx, tcx, did).iter().any(|a| is_doc_hidden(a)) {
256+
if load_attrs(cx, tcx, did).list_def("doc").has_word("hidden") {
263257
return;
264258
}
265259

@@ -288,7 +282,7 @@ pub fn build_impl(cx: &DocContext,
288282
if let Some(ref t) = associated_trait {
289283
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline
290284
let trait_attrs = load_attrs(cx, tcx, t.def_id);
291-
if trait_attrs.iter().any(|a| is_doc_hidden(a)) {
285+
if trait_attrs.list_def("doc").has_word("hidden") {
292286
return
293287
}
294288
}
@@ -428,20 +422,6 @@ pub fn build_impl(cx: &DocContext,
428422
});
429423
}
430424

431-
fn is_doc_hidden(a: &clean::Attribute) -> bool {
432-
match *a {
433-
clean::List(ref name, ref inner) if *name == "doc" => {
434-
inner.iter().any(|a| {
435-
match *a {
436-
clean::Word(ref s) => *s == "hidden",
437-
_ => false,
438-
}
439-
})
440-
}
441-
_ => false
442-
}
443-
}
444-
445425
fn build_module(cx: &DocContext, tcx: &TyCtxt,
446426
did: DefId) -> clean::Module {
447427
let mut items = Vec::new();
@@ -464,9 +444,8 @@ fn build_module(cx: &DocContext, tcx: &TyCtxt,
464444
}
465445
cstore::DlDef(def) if item.vis == hir::Public => {
466446
if !visited.insert(def) { continue }
467-
match try_inline_def(cx, tcx, def) {
468-
Some(i) => items.extend(i),
469-
None => {}
447+
if let Some(i) = try_inline_def(cx, tcx, def) {
448+
items.extend(i)
470449
}
471450
}
472451
cstore::DlDef(..) => {}

0 commit comments

Comments
 (0)