Skip to content

Commit 728ffc8

Browse files
committed
Address review v2
1 parent a3df483 commit 728ffc8

File tree

12 files changed

+60
-68
lines changed

12 files changed

+60
-68
lines changed

src/bootstrap/builder.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -751,11 +751,6 @@ impl<'a> Builder<'a> {
751751
cmd
752752
}
753753

754-
/// Gets a path to the jsondocck tool
755-
pub fn jsondocck(&self, compiler: Compiler, target: TargetSelection) -> PathBuf {
756-
self.ensure(tool::JsonDocCk { compiler, target })
757-
}
758-
759754
/// Return the path to `llvm-config` for the target, if it exists.
760755
///
761756
/// Note that this returns `None` if LLVM is disabled, or if we're in a

src/bootstrap/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
10721072

10731073
cmd.arg("--docck-python").arg(builder.python());
10741074

1075-
cmd.arg("--jsondocck-path").arg(builder.jsondocck(compiler, target));
1075+
cmd.arg("--jsondocck-path").arg(builder.ensure(tool::JsonDocCk { compiler, target }));
10761076

10771077
if builder.config.build.ends_with("apple-darwin") {
10781078
// Force /usr/bin/python3 on macOS for LLDB tests because we're loading the

src/test/rustdoc-json/nested.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
// edition:2018
22

3-
// @has nested.json "$.index.['0:0'].kind" \"module\"
4-
// @has - "$.index.['0:0'].inner.is_crate" true
5-
// @has - "$.index.['0:0'].inner.items[*]" \"0:3\"
3+
// @has nested.json "$.index[*][?(@.name=='nested')].kind" \"module\"
4+
// @has - "$.index[*][?(@.name=='nested')].inner.is_crate" true
5+
// @count - "$.index[*][?(@.name=='nested')].inner.items[*]" 1
66

7-
// @has nested.json "$.index.['0:3'].kind" \"module\"
8-
// @has - "$.index.['0:3'].inner.is_crate" false
9-
// @has - "$.index.['0:3'].inner.items[*]" \"0:4\"
10-
// @has - "$.index.['0:3'].inner.items[*]" \"0:7\"
7+
// @has nested.json "$.index[*][?(@.name=='l1')].kind" \"module\"
8+
// @has - "$.index[*][?(@.name=='l1')].inner.is_crate" false
9+
// @count - "$.index[*][?(@.name=='l1')].inner.items[*]" 2
1110
pub mod l1 {
1211

13-
// @has nested.json "$.index.['0:4'].kind" \"module\"
14-
// @has - "$.index.['0:4'].inner.is_crate" false
15-
// @has - "$.index.['0:4'].inner.items[*]" \"0:5\"
12+
// @has nested.json "$.index[*][?(@.name=='l3')].kind" \"module\"
13+
// @has - "$.index[*][?(@.name=='l3')].inner.is_crate" false
14+
// @count - "$.index[*][?(@.name=='l3')].inner.items[*]" 1
1615
pub mod l3 {
1716

18-
// @has nested.json "$.index.['0:5'].kind" \"struct\"
19-
// @has - "$.index.['0:5'].inner.struct_type" \"unit\"
17+
// @has nested.json "$.index[*][?(@.name=='L4')].kind" \"struct\"
18+
// @has - "$.index[*][?(@.name=='L4')].inner.struct_type" \"unit\"
2019
pub struct L4;
2120
}
22-
// @has nested.json "$.index.['0:7'].kind" \"import\"
23-
// @has - "$.index.['0:7'].inner.glob" false
21+
// @has nested.json "$.index[*][?(@.inner.span=='l3::L4')].kind" \"import\"
22+
// @has - "$.index[*][?(@.inner.span=='l3::L4')].inner.glob" false
2423
pub use l3::L4;
2524
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// @has plain_empty.json "$.index.['0:3'].name" \"PlainEmpty\"
2-
// @has - "$.index.['0:3'].visibility" \"public\"
3-
// @has - "$.index.['0:3'].kind" \"struct\"
4-
// @has - "$.index.['0:3'].inner.struct_type" \"plain\"
5-
// @has - "$.index.['0:3'].inner.fields_stripped" false
6-
// @has - "$.index.['0:3'].inner.fields" []
1+
// @has plain_empty.json "$.index[*][?(@.name=='PlainEmpty')].visibility" \"public\"
2+
// @has - "$.index[*][?(@.name=='PlainEmpty')].kind" \"struct\"
3+
// @has - "$.index[*][?(@.name=='PlainEmpty')].inner.struct_type" \"plain\"
4+
// @has - "$.index[*][?(@.name=='PlainEmpty')].inner.fields_stripped" false
5+
// @has - "$.index[*][?(@.name=='PlainEmpty')].inner.fields" []
76
pub struct PlainEmpty {}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// @has tuple.json "$.index.['0:3'].name" \"Tuple\"
2-
// @has - "$.index.['0:3'].visibility" \"public\"
3-
// @has - "$.index.['0:3'].kind" \"struct\"
4-
// @has - "$.index.['0:3'].inner.struct_type" \"tuple\"
5-
// @has - "$.index.['0:3'].inner.fields_stripped" true
1+
// @has tuple.json "$.index[*][?(@.name=='Tuple')].visibility" \"public\"
2+
// @has - "$.index[*][?(@.name=='Tuple')].kind" \"struct\"
3+
// @has - "$.index[*][?(@.name=='Tuple')].inner.struct_type" \"tuple\"
4+
// @has - "$.index[*][?(@.name=='Tuple')].inner.fields_stripped" true
65
pub struct Tuple(u32, String);

src/test/rustdoc-json/structs/unit.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// @has unit.json "$.index.['0:3'].name" \"Unit\"
2-
// @has - "$.index.['0:3'].visibility" \"public\"
3-
// @has - "$.index.['0:3'].kind" \"struct\"
4-
// @has - "$.index.['0:3'].inner.struct_type" \"unit\"
5-
// @has - "$.index.['0:3'].inner.fields" []
1+
// @has unit.json "$.index[*][?(@.name=='Unit')].visibility" \"public\"
2+
// @has - "$.index[*][?(@.name=='Unit')].kind" \"struct\"
3+
// @has - "$.index[*][?(@.name=='Unit')].inner.struct_type" \"unit\"
4+
// @has - "$.index[*][?(@.name=='Unit')].inner.fields" []
65
pub struct Unit;

src/test/rustdoc-json/structs/with_generics.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::collections::HashMap;
22

3-
// @has with_generics.json "$.index.['0:4'].name" \"WithGenerics\"
4-
// @has - "$.index.['0:4'].visibility" \"public\"
5-
// @has - "$.index.['0:4'].kind" \"struct\"
6-
// @has - "$.index.['0:4'].inner.generics.params[0].name" \"T\"
7-
// @has - "$.index.['0:4'].inner.generics.params[0].kind.type"
8-
// @has - "$.index.['0:4'].inner.generics.params[1].name" \"U\"
9-
// @has - "$.index.['0:4'].inner.generics.params[1].kind.type"
10-
// @has - "$.index.['0:4'].inner.struct_type" \"plain\"
11-
// @has - "$.index.['0:4'].inner.fields_stripped" true
3+
// @has with_generics.json "$.index[*][?(@.name=='WithGenerics')].visibility" \"public\"
4+
// @has - "$.index[*][?(@.name=='WithGenerics')].kind" \"struct\"
5+
// @has - "$.index[*][?(@.name=='WithGenerics')].inner.generics.params[0].name" \"T\"
6+
// @has - "$.index[*][?(@.name=='WithGenerics')].inner.generics.params[0].kind.type"
7+
// @has - "$.index[*][?(@.name=='WithGenerics')].inner.generics.params[1].name" \"U\"
8+
// @has - "$.index[*][?(@.name=='WithGenerics')].inner.generics.params[1].kind.type"
9+
// @has - "$.index[*][?(@.name=='WithGenerics')].inner.struct_type" \"plain\"
10+
// @has - "$.index[*][?(@.name=='WithGenerics')].inner.fields_stripped" true
1211
pub struct WithGenerics<T, U> {
1312
stuff: Vec<T>,
1413
things: HashMap<U, U>,

src/test/rustdoc-json/structs/with_primitives.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// @has with_primitives.json "$.index.['0:3'].name" \"WithPrimitives\"
2-
// @has - "$.index.['0:3'].visibility" \"public\"
3-
// @has - "$.index.['0:3'].kind" \"struct\"
4-
// @has - "$.index.['0:3'].inner.generics.params[0].name" \"\'a\"
5-
// @has - "$.index.['0:3'].inner.generics.params[0].kind" \"lifetime\"
6-
// @has - "$.index.['0:3'].inner.struct_type" \"plain\"
7-
// @has - "$.index.['0:3'].inner.fields_stripped" true
1+
// @has with_primitives.json "$.index[*][?(@.name=='WithPrimitives')].visibility" \"public\"
2+
// @has - "$.index[*][?(@.name=='WithPrimitives')].kind" \"struct\"
3+
// @has - "$.index[*][?(@.name=='WithPrimitives')].inner.generics.params[0].name" \"\'a\"
4+
// @has - "$.index[*][?(@.name=='WithPrimitives')].inner.generics.params[0].kind" \"lifetime\"
5+
// @has - "$.index[*][?(@.name=='WithPrimitives')].inner.struct_type" \"plain\"
6+
// @has - "$.index[*][?(@.name=='WithPrimitives')].inner.fields_stripped" true
87
pub struct WithPrimitives<'a> {
98
num: u32,
109
s: &'a str,

src/tools/compiletest/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
197197
let has_tidy = Command::new("tidy")
198198
.arg("--version")
199199
.stdout(Stdio::null())
200-
.stderr(Stdio::null())
201200
.status()
202201
.map_or(false, |status| status.success());
203202
Config {

src/tools/jsondocck/src/cache.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct Cache {
1313
}
1414

1515
impl Cache {
16+
/// Create a new cache, used to read files only once and otherwise store their contents.
1617
pub fn new(doc_dir: &str) -> Cache {
1718
Cache {
1819
root: Path::new(doc_dir).to_owned(),
@@ -32,9 +33,7 @@ impl Cache {
3233
}
3334
}
3435

35-
pub fn get_file(&mut self, path: &String) -> Result<String, io::Error> {
36-
let path = self.resolve_path(path);
37-
36+
fn read_file(&mut self, path: PathBuf) -> Result<String, io::Error> {
3837
if let Some(f) = self.files.get(&path) {
3938
return Ok(f.clone());
4039
}
@@ -46,16 +45,22 @@ impl Cache {
4645
Ok(file)
4746
}
4847

48+
/// Get the text from a file. If called multiple times, the file will only be read once
49+
pub fn get_file(&mut self, path: &String) -> Result<String, io::Error> {
50+
let path = self.resolve_path(path);
51+
self.read_file(path)
52+
}
53+
54+
/// Parse the JSON from a file. If called multiple times, the file will only be read once.
4955
pub fn get_value(&mut self, path: &String) -> Result<Value, CkError> {
5056
let path = self.resolve_path(path);
5157

5258
if let Some(v) = self.values.get(&path) {
5359
return Ok(v.clone());
5460
}
5561

56-
let file = fs::File::open(&path)?;
57-
58-
let val = serde_json::from_reader::<_, Value>(file)?;
62+
let content = self.read_file(path.clone())?;
63+
let val = serde_json::from_str::<Value>(&content)?;
5964

6065
self.values.insert(path, val.clone());
6166

0 commit comments

Comments
 (0)