Skip to content

Commit 68d576f

Browse files
committed
rustdoc: Fix json output and input
Turns out a hash map with integer keys isn't serializable to json. Closes #10115
1 parent 6db37bb commit 68d576f

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

src/librustdoc/clean.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc::metadata::csearch;
2525
use rustc::metadata::decoder;
2626

2727
use std;
28-
use std::hashmap::HashMap;
2928

3029
use doctree;
3130
use visit_ast;
@@ -68,17 +67,17 @@ impl<T: Clean<U>, U> Clean<~[U]> for syntax::opt_vec::OptVec<T> {
6867
pub struct Crate {
6968
name: ~str,
7069
module: Option<Item>,
71-
externs: HashMap<ast::CrateNum, ExternalCrate>,
70+
externs: ~[(ast::CrateNum, ExternalCrate)],
7271
}
7372

7473
impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
7574
fn clean(&self) -> Crate {
7675
use syntax::attr::find_crateid;
7776
let cx = local_data::get(super::ctxtkey, |x| *x.unwrap());
7877

79-
let mut externs = HashMap::new();
78+
let mut externs = ~[];
8079
cx.sess.cstore.iter_crate_data(|n, meta| {
81-
externs.insert(n, meta.clean());
80+
externs.push((n, meta.clean()));
8281
});
8382

8483
Crate {

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
305305
krate = folder.fold_crate(krate);
306306
}
307307

308-
for (&n, e) in krate.externs.iter() {
308+
for &(n, ref e) in krate.externs.iter() {
309309
cache.extern_locations.insert(n, extern_location(e, &cx.dst));
310310
}
311311

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn json_output(krate: clean::Crate, res: ~[plugins::PluginJson],
344344
};
345345
let crate_json = match json::from_str(crate_json_str) {
346346
Ok(j) => j,
347-
Err(_) => fail!("Rust generated JSON is invalid??")
347+
Err(e) => fail!("Rust generated JSON is invalid: {:?}", e)
348348
};
349349

350350
json.insert(~"crate", crate_json);
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-include ../tools.mk
2+
all:
3+
$(RUSTDOC) -w json -o $(TMPDIR)/doc.json foo.rs
4+
$(RUSTDOC) -o $(TMPDIR)/doc $(TMPDIR)/doc.json

src/test/run-make/rustdoc-json/foo.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[crate_id = "foo#0.1"];
12+
13+
//! Very docs
14+
15+
pub mod bar {
16+
17+
/// So correct
18+
pub mod baz {
19+
/// Much detail
20+
pub fn baz() { }
21+
}
22+
23+
/// *wow*
24+
pub trait Doge { }
25+
}

0 commit comments

Comments
 (0)