From f02f739a825219a4bb5d12df2f646ea67c434a33 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 2 Jun 2014 00:09:44 -0700 Subject: [PATCH] rustdoc: Correctly inline required/provided methods Apparently relying on provided_source in ty::Method is unreliable! Closes #14594 --- src/librustdoc/clean/inline.rs | 19 ++++++++++++------- src/librustdoc/clean/mod.rs | 9 ++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 9a3a68894ab..575dd057867 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -129,7 +129,7 @@ pub fn record_extern_fqn(cx: &core::DocContext, match cx.maybe_typed { core::Typed(ref tcx) => { let fqn = csearch::get_item_path(tcx, did); - let fqn = fqn.move_iter().map(|i| i.to_str().to_string()).collect(); + let fqn = fqn.move_iter().map(|i| i.to_str()).collect(); cx.external_paths.borrow_mut().get_mut_ref().insert(did, (fqn, kind)); } core::NotTyped(..) => {} @@ -138,10 +138,18 @@ pub fn record_extern_fqn(cx: &core::DocContext, pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait { let def = ty::lookup_trait_def(tcx, did); - let methods = ty::trait_methods(tcx, did); + let methods = ty::trait_methods(tcx, did).clean(); + let provided = ty::provided_trait_methods(tcx, did); + let mut methods = methods.move_iter().map(|meth| { + if provided.iter().any(|a| a.def_id == meth.def_id) { + clean::Provided(meth) + } else { + clean::Required(meth) + } + }); clean::Trait { generics: def.generics.clean(), - methods: methods.iter().map(|i| i.clean()).collect(), + methods: methods.collect(), parents: Vec::new(), // FIXME: this is likely wrong } } @@ -263,10 +271,7 @@ fn build_impl(cx: &core::DocContext, if method.vis != ast::Public && associated_trait.is_none() { return None } - let mut item = match ty::method(tcx, *did).clean() { - clean::Provided(item) => item, - clean::Required(item) => item, - }; + let mut item = ty::method(tcx, *did).clean(); item.inner = match item.inner.clone() { clean::TyMethodItem(clean::TyMethod { fn_style, decl, self_, generics diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 856619882c5..a289d767f95 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -942,9 +942,8 @@ fn clean(&self) -> TraitMethod { } } -impl Clean for ty::Method { - fn clean(&self) -> TraitMethod { - let m = if self.provided_source.is_some() {Provided} else {Required}; +impl Clean for ty::Method { + fn clean(&self) -> Item { let cx = super::ctxtkey.get().unwrap(); let tcx = match cx.maybe_typed { core::Typed(ref tcx) => tcx, @@ -972,7 +971,7 @@ fn clean(&self) -> TraitMethod { } }; - m(Item { + Item { name: Some(self.ident.clean()), visibility: Some(ast::Inherited), def_id: self.def_id, @@ -984,7 +983,7 @@ fn clean(&self) -> TraitMethod { self_: self_, decl: (self.def_id, &sig).clean(), }) - }) + } } } -- 2.44.0