]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Correctly inline required/provided methods
authorAlex Crichton <alex@alexcrichton.com>
Mon, 2 Jun 2014 07:09:44 +0000 (00:09 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 2 Jun 2014 16:18:32 +0000 (09:18 -0700)
Apparently relying on provided_source in ty::Method is unreliable!

Closes #14594

src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs

index 9a3a68894ab517c898c743696d8fdb544236a31a..575dd057867fb24b7e7df3d5ce3058c5aa7ba5f2 100644 (file)
@@ -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
index 856619882c574b18753448b26909c2c04e600e9f..a289d767f95ece2e241363ac88dd7b8bac30d3e4 100644 (file)
@@ -942,9 +942,8 @@ fn clean(&self) -> TraitMethod {
     }
 }
 
-impl Clean<TraitMethod> for ty::Method {
-    fn clean(&self) -> TraitMethod {
-        let m = if self.provided_source.is_some() {Provided} else {Required};
+impl Clean<Item> 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(),
             })
-        })
+        }
     }
 }