Skip to content

Commit c254a15

Browse files
committedDec 5, 2020
Use true ID for def_id.
·
1.88.01.50.0
1 parent 2218520 commit c254a15

File tree

5 files changed

+249
-41
lines changed

5 files changed

+249
-41
lines changed
 

‎src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22632263
name: None,
22642264
attrs: self.attrs.clean(cx),
22652265
source: self.span.clean(cx),
2266-
def_id: DefId::local(CRATE_DEF_INDEX),
2266+
def_id: cx.tcx.hir().local_def_id(self.id).to_def_id(),
22672267
visibility: self.vis.clean(cx),
22682268
stability: None,
22692269
const_stability: None,

‎src/librustdoc/json/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ impl FormatRenderer for JsonRenderer {
151151
} else if let types::ItemEnum::EnumItem(ref mut e) = new_item.inner {
152152
e.impls = self.get_impls(id, cache)
153153
}
154-
self.index.borrow_mut().insert(id.into(), new_item);
154+
let removed = self.index.borrow_mut().insert(id.into(), new_item.clone());
155+
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
156+
// to make sure the items are unique.
157+
if let Some(old_item) = removed {
158+
assert_eq!(old_item, new_item);
159+
}
155160
}
156161

157162
Ok(())

‎src/librustdoc/json/types.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
1111
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
1212
/// about the language items in the local crate, as well as info about external items to allow
1313
/// tools to find or link to them.
14-
#[derive(Clone, Debug, Serialize, Deserialize)]
14+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
1515
pub struct Crate {
1616
/// The id of the root [`Module`] item of the local crate.
1717
pub root: Id,
@@ -31,7 +31,7 @@ pub struct Crate {
3131
pub format_version: u32,
3232
}
3333

34-
#[derive(Clone, Debug, Serialize, Deserialize)]
34+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
3535
pub struct ExternalCrate {
3636
pub name: String,
3737
pub html_root_url: Option<String>,
@@ -41,7 +41,7 @@ pub struct ExternalCrate {
4141
/// information. This struct should contain enough to generate a link/reference to the item in
4242
/// question, or can be used by a tool that takes the json output of multiple crates to find
4343
/// the actual item definition with all the relevant info.
44-
#[derive(Clone, Debug, Serialize, Deserialize)]
44+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
4545
pub struct ItemSummary {
4646
/// Can be used to look up the name and html_root_url of the crate this item came from in the
4747
/// `external_crates` map.
@@ -53,7 +53,7 @@ pub struct ItemSummary {
5353
pub kind: ItemKind,
5454
}
5555

56-
#[derive(Clone, Debug, Serialize, Deserialize)]
56+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
5757
pub struct Item {
5858
/// The unique identifier of this item. Can be used to find this item in various mappings.
5959
pub id: Id,
@@ -79,7 +79,7 @@ pub struct Item {
7979
pub inner: ItemEnum,
8080
}
8181

82-
#[derive(Clone, Debug, Serialize, Deserialize)]
82+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
8383
pub struct Span {
8484
/// The path to the source file for this span relative to the path `rustdoc` was invoked with.
8585
pub filename: PathBuf,
@@ -89,14 +89,14 @@ pub struct Span {
8989
pub end: (usize, usize),
9090
}
9191

92-
#[derive(Clone, Debug, Serialize, Deserialize)]
92+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
9393
pub struct Deprecation {
9494
pub since: Option<String>,
9595
pub note: Option<String>,
9696
}
9797

9898
#[serde(rename_all = "snake_case")]
99-
#[derive(Clone, Debug, Serialize, Deserialize)]
99+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
100100
pub enum Visibility {
101101
Public,
102102
/// For the most part items are private by default. The exceptions are associated items of
@@ -112,7 +112,7 @@ pub enum Visibility {
112112
}
113113

114114
#[serde(rename_all = "snake_case")]
115-
#[derive(Clone, Debug, Serialize, Deserialize)]
115+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
116116
pub enum GenericArgs {
117117
/// <'a, 32, B: Copy, C = u32>
118118
AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },
@@ -121,14 +121,14 @@ pub enum GenericArgs {
121121
}
122122

123123
#[serde(rename_all = "snake_case")]
124-
#[derive(Clone, Debug, Serialize, Deserialize)]
124+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
125125
pub enum GenericArg {
126126
Lifetime(String),
127127
Type(Type),
128128
Const(Constant),
129129
}
130130

131-
#[derive(Clone, Debug, Serialize, Deserialize)]
131+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
132132
pub struct Constant {
133133
#[serde(rename = "type")]
134134
pub type_: Type,
@@ -137,14 +137,14 @@ pub struct Constant {
137137
pub is_literal: bool,
138138
}
139139

140-
#[derive(Clone, Debug, Serialize, Deserialize)]
140+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
141141
pub struct TypeBinding {
142142
pub name: String,
143143
pub binding: TypeBindingKind,
144144
}
145145

146146
#[serde(rename_all = "snake_case")]
147-
#[derive(Clone, Debug, Serialize, Deserialize)]
147+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
148148
pub enum TypeBindingKind {
149149
Equality(Type),
150150
Constraint(Vec<GenericBound>),
@@ -154,7 +154,7 @@ pub enum TypeBindingKind {
154154
pub struct Id(pub String);
155155

156156
#[serde(rename_all = "snake_case")]
157-
#[derive(Clone, Debug, Serialize, Deserialize)]
157+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
158158
pub enum ItemKind {
159159
Module,
160160
ExternCrate,
@@ -184,7 +184,7 @@ pub enum ItemKind {
184184
}
185185

186186
#[serde(untagged)]
187-
#[derive(Clone, Debug, Serialize, Deserialize)]
187+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
188188
pub enum ItemEnum {
189189
ModuleItem(Module),
190190
ExternCrateItem {
@@ -231,13 +231,13 @@ pub enum ItemEnum {
231231
},
232232
}
233233

234-
#[derive(Clone, Debug, Serialize, Deserialize)]
234+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
235235
pub struct Module {
236236
pub is_crate: bool,
237237
pub items: Vec<Id>,
238238
}
239239

240-
#[derive(Clone, Debug, Serialize, Deserialize)]
240+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
241241
pub struct Struct {
242242
pub struct_type: StructType,
243243
pub generics: Generics,
@@ -246,7 +246,7 @@ pub struct Struct {
246246
pub impls: Vec<Id>,
247247
}
248248

249-
#[derive(Clone, Debug, Serialize, Deserialize)]
249+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
250250
pub struct Enum {
251251
pub generics: Generics,
252252
pub variants_stripped: bool,
@@ -256,67 +256,67 @@ pub struct Enum {
256256

257257
#[serde(rename_all = "snake_case")]
258258
#[serde(tag = "variant_kind", content = "variant_inner")]
259-
#[derive(Clone, Debug, Serialize, Deserialize)]
259+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
260260
pub enum Variant {
261261
Plain,
262262
Tuple(Vec<Type>),
263263
Struct(Vec<Id>),
264264
}
265265

266266
#[serde(rename_all = "snake_case")]
267-
#[derive(Clone, Debug, Serialize, Deserialize)]
267+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
268268
pub enum StructType {
269269
Plain,
270270
Tuple,
271271
Unit,
272272
}
273273

274-
#[derive(Clone, Debug, Serialize, Deserialize)]
274+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
275275
pub struct Function {
276276
pub decl: FnDecl,
277277
pub generics: Generics,
278278
pub header: String,
279279
pub abi: String,
280280
}
281281

282-
#[derive(Clone, Debug, Serialize, Deserialize)]
282+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
283283
pub struct Method {
284284
pub decl: FnDecl,
285285
pub generics: Generics,
286286
pub header: String,
287287
pub has_body: bool,
288288
}
289289

290-
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
290+
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
291291
pub struct Generics {
292292
pub params: Vec<GenericParamDef>,
293293
pub where_predicates: Vec<WherePredicate>,
294294
}
295295

296-
#[derive(Clone, Debug, Serialize, Deserialize)]
296+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
297297
pub struct GenericParamDef {
298298
pub name: String,
299299
pub kind: GenericParamDefKind,
300300
}
301301

302302
#[serde(rename_all = "snake_case")]
303-
#[derive(Clone, Debug, Serialize, Deserialize)]
303+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
304304
pub enum GenericParamDefKind {
305305
Lifetime,
306306
Type { bounds: Vec<GenericBound>, default: Option<Type> },
307307
Const(Type),
308308
}
309309

310310
#[serde(rename_all = "snake_case")]
311-
#[derive(Clone, Debug, Serialize, Deserialize)]
311+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
312312
pub enum WherePredicate {
313313
BoundPredicate { ty: Type, bounds: Vec<GenericBound> },
314314
RegionPredicate { lifetime: String, bounds: Vec<GenericBound> },
315315
EqPredicate { lhs: Type, rhs: Type },
316316
}
317317

318318
#[serde(rename_all = "snake_case")]
319-
#[derive(Clone, Debug, Serialize, Deserialize)]
319+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
320320
pub enum GenericBound {
321321
TraitBound {
322322
#[serde(rename = "trait")]
@@ -329,7 +329,7 @@ pub enum GenericBound {
329329
}
330330

331331
#[serde(rename_all = "snake_case")]
332-
#[derive(Clone, Debug, Serialize, Deserialize)]
332+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
333333
pub enum TraitBoundModifier {
334334
None,
335335
Maybe,
@@ -338,7 +338,7 @@ pub enum TraitBoundModifier {
338338

339339
#[serde(rename_all = "snake_case")]
340340
#[serde(tag = "kind", content = "inner")]
341-
#[derive(Clone, Debug, Serialize, Deserialize)]
341+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
342342
pub enum Type {
343343
/// Structs, enums, and traits
344344
ResolvedPath {
@@ -391,22 +391,22 @@ pub enum Type {
391391
},
392392
}
393393

394-
#[derive(Clone, Debug, Serialize, Deserialize)]
394+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
395395
pub struct FunctionPointer {
396396
pub is_unsafe: bool,
397397
pub generic_params: Vec<GenericParamDef>,
398398
pub decl: FnDecl,
399399
pub abi: String,
400400
}
401401

402-
#[derive(Clone, Debug, Serialize, Deserialize)]
402+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
403403
pub struct FnDecl {
404404
pub inputs: Vec<(String, Type)>,
405405
pub output: Option<Type>,
406406
pub c_variadic: bool,
407407
}
408408

409-
#[derive(Clone, Debug, Serialize, Deserialize)]
409+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
410410
pub struct Trait {
411411
pub is_auto: bool,
412412
pub is_unsafe: bool,
@@ -416,13 +416,13 @@ pub struct Trait {
416416
pub implementors: Vec<Id>,
417417
}
418418

419-
#[derive(Clone, Debug, Serialize, Deserialize)]
419+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
420420
pub struct TraitAlias {
421421
pub generics: Generics,
422422
pub params: Vec<GenericBound>,
423423
}
424424

425-
#[derive(Clone, Debug, Serialize, Deserialize)]
425+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
426426
pub struct Impl {
427427
pub is_unsafe: bool,
428428
pub generics: Generics,
@@ -438,7 +438,7 @@ pub struct Impl {
438438
}
439439

440440
#[serde(rename_all = "snake_case")]
441-
#[derive(Clone, Debug, Serialize, Deserialize)]
441+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
442442
pub struct Import {
443443
/// The full path being imported.
444444
pub span: String,
@@ -451,14 +451,14 @@ pub struct Import {
451451
pub glob: bool,
452452
}
453453

454-
#[derive(Clone, Debug, Serialize, Deserialize)]
454+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
455455
pub struct ProcMacro {
456456
pub kind: MacroKind,
457457
pub helpers: Vec<String>,
458458
}
459459

460460
#[serde(rename_all = "snake_case")]
461-
#[derive(Clone, Debug, Serialize, Deserialize)]
461+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
462462
pub enum MacroKind {
463463
/// A bang macro `foo!()`.
464464
Bang,
@@ -468,20 +468,20 @@ pub enum MacroKind {
468468
Derive,
469469
}
470470

471-
#[derive(Clone, Debug, Serialize, Deserialize)]
471+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
472472
pub struct Typedef {
473473
#[serde(rename = "type")]
474474
pub type_: Type,
475475
pub generics: Generics,
476476
}
477477

478-
#[derive(Clone, Debug, Serialize, Deserialize)]
478+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
479479
pub struct OpaqueTy {
480480
pub bounds: Vec<GenericBound>,
481481
pub generics: Generics,
482482
}
483483

484-
#[derive(Clone, Debug, Serialize, Deserialize)]
484+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
485485
pub struct Static {
486486
#[serde(rename = "type")]
487487
pub type_: Type,

‎src/test/rustdoc-json/nested.expected

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
{
2+
"crate_version": null,
3+
"external_crates": {},
4+
"format_version": 1,
5+
"includes_private": false,
6+
"index": {
7+
"0:0": {
8+
"attrs": [],
9+
"crate_id": 0,
10+
"deprecation": null,
11+
"docs": "",
12+
"id": "0:0",
13+
"inner": {
14+
"is_crate": true,
15+
"items": [
16+
"0:3"
17+
]
18+
},
19+
"kind": "module",
20+
"links": {},
21+
"name": "nested",
22+
"source": {
23+
"begin": [
24+
2,
25+
0
26+
],
27+
"end": [
28+
7,
29+
1
30+
],
31+
"filename": "$TEST_BASE_DIR/nested.rs"
32+
},
33+
"visibility": "public"
34+
},
35+
"0:3": {
36+
"attrs": [],
37+
"crate_id": 0,
38+
"deprecation": null,
39+
"docs": "",
40+
"id": "0:3",
41+
"inner": {
42+
"is_crate": false,
43+
"items": [
44+
"0:7",
45+
"0:4"
46+
]
47+
},
48+
"kind": "module",
49+
"links": {},
50+
"name": "l1",
51+
"source": {
52+
"begin": [
53+
2,
54+
0
55+
],
56+
"end": [
57+
7,
58+
1
59+
],
60+
"filename": "$TEST_BASE_DIR/nested.rs"
61+
},
62+
"visibility": "public"
63+
},
64+
"0:4": {
65+
"attrs": [],
66+
"crate_id": 0,
67+
"deprecation": null,
68+
"docs": "",
69+
"id": "0:4",
70+
"inner": {
71+
"is_crate": false,
72+
"items": [
73+
"0:5"
74+
]
75+
},
76+
"kind": "module",
77+
"links": {},
78+
"name": "l3",
79+
"source": {
80+
"begin": [
81+
3,
82+
4
83+
],
84+
"end": [
85+
5,
86+
5
87+
],
88+
"filename": "$TEST_BASE_DIR/nested.rs"
89+
},
90+
"visibility": "public"
91+
},
92+
"0:5": {
93+
"attrs": [],
94+
"crate_id": 0,
95+
"deprecation": null,
96+
"docs": "",
97+
"id": "0:5",
98+
"inner": {
99+
"fields": [],
100+
"fields_stripped": false,
101+
"generics": {
102+
"params": [],
103+
"where_predicates": []
104+
},
105+
"impls": [
106+
"0:10",
107+
"0:11",
108+
"0:12",
109+
"0:14",
110+
"0:15"
111+
],
112+
"struct_type": "unit"
113+
},
114+
"kind": "struct",
115+
"links": {},
116+
"name": "L4",
117+
"source": {
118+
"begin": [
119+
4,
120+
8
121+
],
122+
"end": [
123+
4,
124+
22
125+
],
126+
"filename": "$TEST_BASE_DIR/nested.rs"
127+
},
128+
"visibility": "public"
129+
},
130+
"0:7": {
131+
"attrs": [],
132+
"crate_id": 0,
133+
"deprecation": null,
134+
"docs": "",
135+
"id": "0:7",
136+
"inner": {
137+
"glob": false,
138+
"id": "0:5",
139+
"name": "L4",
140+
"span": "l3::L4"
141+
},
142+
"kind": "import",
143+
"links": {},
144+
"name": null,
145+
"source": {
146+
"begin": [
147+
6,
148+
4
149+
],
150+
"end": [
151+
6,
152+
19
153+
],
154+
"filename": "$TEST_BASE_DIR/nested.rs"
155+
},
156+
"visibility": "public"
157+
}
158+
},
159+
"paths": {
160+
"0:0": {
161+
"crate_id": 0,
162+
"kind": "module",
163+
"path": [
164+
"nested"
165+
]
166+
},
167+
"0:3": {
168+
"crate_id": 0,
169+
"kind": "module",
170+
"path": [
171+
"nested",
172+
"l1"
173+
]
174+
},
175+
"0:4": {
176+
"crate_id": 0,
177+
"kind": "module",
178+
"path": [
179+
"nested",
180+
"l1",
181+
"l3"
182+
]
183+
},
184+
"0:5": {
185+
"crate_id": 0,
186+
"kind": "struct",
187+
"path": [
188+
"nested",
189+
"l1",
190+
"l3",
191+
"L4"
192+
]
193+
}
194+
},
195+
"root": "0:0"
196+
}

‎src/test/rustdoc-json/nested.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// edition:2018
2+
pub mod l1 {
3+
pub mod l3 {
4+
pub struct L4;
5+
}
6+
pub use l3::L4;
7+
}

0 commit comments

Comments
 (0)
Please sign in to comment.