Skip to content

Commit c254a15

Browse files
committed
Use true ID for def_id.
1 parent 2218520 commit c254a15

File tree

5 files changed

+249
-41
lines changed

5 files changed

+249
-41
lines changed

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

+1-1
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,

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

+6-1
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(())

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

+39-39
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,

0 commit comments

Comments
 (0)