Skip to content

Commit 6b9b2bd

Browse files
committed
Auto merge of rust-lang#94921 - aDotInTheVoid:rustdoc-json-format-cleanup, r=CraftSpider
rustdoc-json: Clean Up json format No semantic changes, but better names Closes rust-lang#94198 Closes rust-lang#94889 r? `@CraftSpider` `@rustbot` modify labels: +A-rustdoc-json +T-rustdoc +C-cleanup
2 parents 3f58828 + a5c0b14 commit 6b9b2bd

File tree

6 files changed

+49
-16
lines changed

6 files changed

+49
-16
lines changed

Diff for: src/etc/check_missing_items.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def check_generics(generics):
3131
for where_predicate in generics["where_predicates"]:
3232
if "bound_predicate" in where_predicate:
3333
pred = where_predicate["bound_predicate"]
34-
check_type(pred["ty"])
34+
check_type(pred["type"])
3535
for bound in pred["bounds"]:
3636
check_generic_bound(bound)
3737
elif "region_predicate" in where_predicate:
@@ -171,7 +171,7 @@ def check_type(ty):
171171
for bound in item["inner"]["bounds"]:
172172
check_generic_bound(bound)
173173
work_list |= (
174-
set(item["inner"]["items"]) | set(item["inner"]["implementors"])
174+
set(item["inner"]["items"]) | set(item["inner"]["implementations"])
175175
) - visited
176176
elif item["kind"] == "impl":
177177
check_generics(item["inner"]["generics"])

Diff for: src/librustdoc/json/conversions.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,10 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
345345
default: default.map(|x| (*x).into_tcx(tcx)),
346346
synthetic,
347347
},
348-
Const { did: _, ty, default } => {
349-
GenericParamDefKind::Const { ty: (*ty).into_tcx(tcx), default: default.map(|x| *x) }
350-
}
348+
Const { did: _, ty, default } => GenericParamDefKind::Const {
349+
type_: (*ty).into_tcx(tcx),
350+
default: default.map(|x| *x),
351+
},
351352
}
352353
}
353354
}
@@ -357,7 +358,7 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
357358
use clean::WherePredicate::*;
358359
match predicate {
359360
BoundPredicate { ty, bounds, .. } => WherePredicate::BoundPredicate {
360-
ty: ty.into_tcx(tcx),
361+
type_: ty.into_tcx(tcx),
361362
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
362363
// FIXME: add `bound_params` to rustdoc-json-params?
363364
},
@@ -516,7 +517,7 @@ impl FromWithTcx<clean::Trait> for Trait {
516517
items: ids(items),
517518
generics: generics.into_tcx(tcx),
518519
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
519-
implementors: Vec::new(), // Added in JsonRenderer::item
520+
implementations: Vec::new(), // Added in JsonRenderer::item
520521
}
521522
}
522523
}

Diff for: src/librustdoc/json/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
179179
let id = item.def_id;
180180
if let Some(mut new_item) = self.convert_item(item) {
181181
if let types::ItemEnum::Trait(ref mut t) = new_item.inner {
182-
t.implementors = self.get_trait_implementors(id.expect_def_id())
182+
t.implementations = self.get_trait_implementors(id.expect_def_id())
183183
} else if let types::ItemEnum::Struct(ref mut s) = new_item.inner {
184184
s.impls = self.get_impls(id.expect_def_id())
185185
} else if let types::ItemEnum::Enum(ref mut e) = new_item.inner {

Diff for: src/rustdoc-json-types/lib.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use serde::{Deserialize, Serialize};
1010

1111
/// rustdoc format-version.
12-
pub const FORMAT_VERSION: u32 = 13;
12+
pub const FORMAT_VERSION: u32 = 14;
1313

1414
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
1515
/// about the language items in the local crate, as well as info about external items to allow
@@ -378,17 +378,28 @@ pub enum GenericParamDefKind {
378378
synthetic: bool,
379379
},
380380
Const {
381-
ty: Type,
381+
#[serde(rename = "type")]
382+
type_: Type,
382383
default: Option<String>,
383384
},
384385
}
385386

386387
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
387388
#[serde(rename_all = "snake_case")]
388389
pub enum WherePredicate {
389-
BoundPredicate { ty: Type, bounds: Vec<GenericBound> },
390-
RegionPredicate { lifetime: String, bounds: Vec<GenericBound> },
391-
EqPredicate { lhs: Type, rhs: Term },
390+
BoundPredicate {
391+
#[serde(rename = "type")]
392+
type_: Type,
393+
bounds: Vec<GenericBound>,
394+
},
395+
RegionPredicate {
396+
lifetime: String,
397+
bounds: Vec<GenericBound>,
398+
},
399+
EqPredicate {
400+
lhs: Type,
401+
rhs: Term,
402+
},
392403
}
393404

394405
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
@@ -494,7 +505,7 @@ pub struct Trait {
494505
pub items: Vec<Id>,
495506
pub generics: Generics,
496507
pub bounds: Vec<GenericBound>,
497-
pub implementors: Vec<Id>,
508+
pub implementations: Vec<Id>,
498509
}
499510

500511
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]

Diff for: src/test/rustdoc-json/generic-associated-types/gats.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ pub trait LendingIterator {
1313
// @count - "$.index[*][?(@.name=='LendingItem')].inner.generics.params[*]" 1
1414
// @is - "$.index[*][?(@.name=='LendingItem')].inner.generics.params[*].name" \"\'a\"
1515
// @count - "$.index[*][?(@.name=='LendingItem')].inner.generics.where_predicates[*]" 1
16-
// @is - "$.index[*][?(@.name=='LendingItem')].inner.generics.where_predicates[*].bound_predicate.ty.inner" \"Self\"
16+
// @is - "$.index[*][?(@.name=='LendingItem')].inner.generics.where_predicates[*].bound_predicate.type.inner" \"Self\"
1717
// @is - "$.index[*][?(@.name=='LendingItem')].inner.generics.where_predicates[*].bound_predicate.bounds[*].outlives" \"\'a\"
1818
// @count - "$.index[*][?(@.name=='LendingItem')].inner.bounds[*]" 1
19-
type LendingItem<'a>: Display where Self: 'a;
19+
type LendingItem<'a>: Display
20+
where
21+
Self: 'a;
2022

2123
// @is - "$.index[*][?(@.name=='lending_next')].inner.decl.output.kind" \"qualified_path\"
2224
// @count - "$.index[*][?(@.name=='lending_next')].inner.decl.output.inner.args.angle_bracketed.args[*]" 1

Diff for: src/test/rustdoc-json/traits/implementors.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
// @set wham = implementors.json "$.index[*][?(@.name=='Wham')].id"
5+
// @count - "$.index[*][?(@.name=='Wham')].inner.implementations[*]" 1
6+
// @set gmWham = - "$.index[*][?(@.name=='Wham')].inner.implementations[0]"
7+
pub trait Wham {}
8+
9+
// @count - "$.index[*][?(@.name=='GeorgeMichael')].inner.impls[*]" 1
10+
// @is - "$.index[*][?(@.name=='GeorgeMichael')].inner.impls[0]" $gmWham
11+
// @set gm = - "$.index[*][?(@.name=='Wham')].id"
12+
13+
// jsonpath_lib isnt expressive enough (for now) to get the "impl" item, so we
14+
// just check it isn't pointing to the type, but when you port to jsondocck-ng
15+
// check what the impl item is
16+
// @!is - "$.index[*][?(@.name=='Wham')].inner.implementations[0]" $gm
17+
pub struct GeorgeMichael {}
18+
19+
impl Wham for GeorgeMichael {}

0 commit comments

Comments
 (0)