about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-02-16 22:31:05 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-02-19 01:10:31 -0800
commit68d576fd345b197e5be08cc9b84201e5897dc729 (patch)
tree25ebea7acdf107ddf61e5412dd9e2e7de6245937 /src
parent6db37bb147c06cddf7ae6a99eb913a5ceaee792b (diff)
downloadrust-68d576fd345b197e5be08cc9b84201e5897dc729.tar.gz
rust-68d576fd345b197e5be08cc9b84201e5897dc729.zip
rustdoc: Fix json output and input
Turns out a hash map with integer keys isn't serializable to json.

Closes #10115
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean.rs7
-rw-r--r--src/librustdoc/html/render.rs2
-rw-r--r--src/librustdoc/lib.rs2
-rw-r--r--src/test/run-make/rustdoc-json/Makefile4
-rw-r--r--src/test/run-make/rustdoc-json/foo.rs25
5 files changed, 34 insertions, 6 deletions
diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs
index c0c146319cb..586323358c2 100644
--- a/src/librustdoc/clean.rs
+++ b/src/librustdoc/clean.rs
@@ -25,7 +25,6 @@ use rustc::metadata::csearch;
 use rustc::metadata::decoder;
 
 use std;
-use std::hashmap::HashMap;
 
 use doctree;
 use visit_ast;
@@ -68,7 +67,7 @@ impl<T: Clean<U>, U> Clean<~[U]> for syntax::opt_vec::OptVec<T> {
 pub struct Crate {
     name: ~str,
     module: Option<Item>,
-    externs: HashMap<ast::CrateNum, ExternalCrate>,
+    externs: ~[(ast::CrateNum, ExternalCrate)],
 }
 
 impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
@@ -76,9 +75,9 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
         use syntax::attr::find_crateid;
         let cx = local_data::get(super::ctxtkey, |x| *x.unwrap());
 
-        let mut externs = HashMap::new();
+        let mut externs = ~[];
         cx.sess.cstore.iter_crate_data(|n, meta| {
-            externs.insert(n, meta.clean());
+            externs.push((n, meta.clean()));
         });
 
         Crate {
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 5299b31ac7b..07ea22d42ec 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -305,7 +305,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
         krate = folder.fold_crate(krate);
     }
 
-    for (&n, e) in krate.externs.iter() {
+    for &(n, ref e) in krate.externs.iter() {
         cache.extern_locations.insert(n, extern_location(e, &cx.dst));
     }
 
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 2c4d553a39f..4194f5e4729 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -344,7 +344,7 @@ fn json_output(krate: clean::Crate, res: ~[plugins::PluginJson],
     };
     let crate_json = match json::from_str(crate_json_str) {
         Ok(j) => j,
-        Err(_) => fail!("Rust generated JSON is invalid??")
+        Err(e) => fail!("Rust generated JSON is invalid: {:?}", e)
     };
 
     json.insert(~"crate", crate_json);
diff --git a/src/test/run-make/rustdoc-json/Makefile b/src/test/run-make/rustdoc-json/Makefile
new file mode 100644
index 00000000000..5e6ab4b790e
--- /dev/null
+++ b/src/test/run-make/rustdoc-json/Makefile
@@ -0,0 +1,4 @@
+-include ../tools.mk
+all:
+	$(RUSTDOC) -w json -o $(TMPDIR)/doc.json foo.rs
+	$(RUSTDOC) -o $(TMPDIR)/doc $(TMPDIR)/doc.json
diff --git a/src/test/run-make/rustdoc-json/foo.rs b/src/test/run-make/rustdoc-json/foo.rs
new file mode 100644
index 00000000000..818ec1e5eb7
--- /dev/null
+++ b/src/test/run-make/rustdoc-json/foo.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[crate_id = "foo#0.1"];
+
+//! Very docs
+
+pub mod bar {
+
+    /// So correct
+    pub mod baz {
+        /// Much detail
+        pub fn baz() { }
+    }
+
+    /// *wow*
+    pub trait Doge { }
+}