about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-07-25 09:31:20 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-07-25 10:24:26 -0700
commit431622e1e202467e0ba61cdf2df7ceb501926547 (patch)
tree0c6c396fab9f58dd9d33b7995b71af225272f5d9
parent15a727bba1b3a93d58c786460de6926c138d9507 (diff)
downloadrust-431622e1e202467e0ba61cdf2df7ceb501926547.tar.gz
rust-431622e1e202467e0ba61cdf2df7ceb501926547.zip
rustdoc: Fix links to Box/Gc
These are lang items now, so the internal representations need to be
re-translated back to the original structures manually.

Closes #15185
Closes #15800
-rw-r--r--src/librustdoc/clean/mod.rs56
-rw-r--r--src/librustdoc/html/format.rs6
2 files changed, 48 insertions, 14 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 05b91c5ddf9..5b59eed9321 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -747,7 +747,6 @@ pub enum SelfTy {
     SelfStatic,
     SelfValue,
     SelfBorrowed(Option<Lifetime>, Mutability),
-    SelfOwned,
     SelfExplicit(Type),
 }
 
@@ -971,28 +970,27 @@ impl Clean<Item> for ty::Method {
     fn clean(&self) -> Item {
         let cx = get_cx();
         let (self_, sig) = match self.explicit_self {
-            ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(), self.fty.sig.clone()),
+            ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(),
+                                               self.fty.sig.clone()),
             s => {
                 let sig = ty::FnSig {
                     inputs: Vec::from_slice(self.fty.sig.inputs.slice_from(1)),
                     ..self.fty.sig.clone()
                 };
                 let s = match s {
+                    ty::ByValueExplicitSelfCategory => SelfValue,
                     ty::ByReferenceExplicitSelfCategory(..) => {
                         match ty::get(self.fty.sig.inputs[0]).sty {
                             ty::ty_rptr(r, mt) => {
                                 SelfBorrowed(r.clean(), mt.mutbl.clean())
                             }
-                            _ => {
-                                // FIXME(pcwalton): This is wrong.
-                                SelfStatic
-                            }
+                            _ => unreachable!(),
                         }
                     }
-                    _ => {
-                        // FIXME(pcwalton): This is wrong.
-                        SelfStatic
+                    ty::ByBoxExplicitSelfCategory => {
+                        SelfExplicit(self.fty.sig.inputs[0].clean())
                     }
+                    ty::StaticExplicitSelfCategory => unreachable!(),
                 };
                 (s, sig)
             }
@@ -1213,8 +1211,18 @@ impl Clean<Type> for ty::t {
             ty::ty_float(ast::TyF32) => Primitive(F32),
             ty::ty_float(ast::TyF64) => Primitive(F64),
             ty::ty_str => Primitive(Str),
-            ty::ty_box(t) => Managed(box t.clean()),
-            ty::ty_uniq(t) => Unique(box t.clean()),
+            ty::ty_box(t) => {
+                let gc_did = get_cx().tcx_opt().and_then(|tcx| {
+                    tcx.lang_items.gc()
+                });
+                lang_struct(gc_did, t, "Gc", Managed)
+            }
+            ty::ty_uniq(t) => {
+                let box_did = get_cx().tcx_opt().and_then(|tcx| {
+                    tcx.lang_items.owned_box()
+                });
+                lang_struct(box_did, t, "Box", Unique)
+            }
             ty::ty_vec(mt, None) => Vector(box mt.ty.clean()),
             ty::ty_vec(mt, Some(i)) => FixedVector(box mt.ty.clean(),
                                                    format!("{}", i)),
@@ -2094,3 +2102,29 @@ impl Clean<Stability> for attr::Stability {
         }
     }
 }
+
+fn lang_struct(did: Option<ast::DefId>, t: ty::t, name: &str,
+               fallback: fn(Box<Type>) -> Type) -> Type {
+    let did = match did {
+        Some(did) => did,
+        None => return fallback(box t.clean()),
+    };
+    let fqn = csearch::get_item_path(get_cx().tcx(), did);
+    let fqn: Vec<String> = fqn.move_iter().map(|i| {
+        i.to_string()
+    }).collect();
+    get_cx().external_paths.borrow_mut().get_mut_ref()
+                           .insert(did, (fqn, TypeStruct));
+    ResolvedPath {
+        typarams: None,
+        did: did,
+        path: Path {
+            global: false,
+            segments: vec![PathSegment {
+                name: name.to_string(),
+                lifetimes: vec![],
+                types: vec![t.clean()],
+            }],
+        },
+    }
+}
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index e7f93703399..c6d6843db5f 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -444,8 +444,6 @@ impl fmt::Show for clean::Type {
                                format!("[{}, ..{}]", **t, *s).as_slice())
             }
             clean::Bottom => f.write("!".as_bytes()),
-            clean::Unique(ref t) => write!(f, "Box<{}>", **t),
-            clean::Managed(ref t) => write!(f, "Gc<{}>", **t),
             clean::RawPointer(m, ref t) => {
                 write!(f, "*{}{}", RawMutableSpace(m), **t)
             }
@@ -456,6 +454,9 @@ impl fmt::Show for clean::Type {
                 };
                 write!(f, "&amp;{}{}{}", lt, MutableSpace(mutability), **ty)
             }
+            clean::Unique(..) | clean::Managed(..) => {
+                fail!("should have been cleaned")
+            }
         }
     }
 }
@@ -491,7 +492,6 @@ impl<'a> fmt::Show for Method<'a> {
         match *selfty {
             clean::SelfStatic => {},
             clean::SelfValue => args.push_str("self"),
-            clean::SelfOwned => args.push_str("self: Box<Self>"),
             clean::SelfBorrowed(Some(ref lt), mtbl) => {
                 args.push_str(format!("&amp;{} {}self", *lt,
                                       MutableSpace(mtbl)).as_slice());