@@ -8,13 +8,14 @@ use rustdoc_json_types::{
8
8
TypeBindingKind , Typedef , Union , Variant , WherePredicate ,
9
9
} ;
10
10
11
- use crate :: { item_kind:: Kind , Error } ;
11
+ use crate :: { item_kind:: Kind , Error , ErrorKind } ;
12
12
13
13
#[ derive( Debug ) ]
14
14
pub struct Validator < ' a > {
15
15
pub ( crate ) errs : Vec < Error > ,
16
16
krate : & ' a Crate ,
17
17
seen_ids : HashSet < & ' a Id > ,
18
+ missing_ids : HashSet < & ' a Id > ,
18
19
todo : HashSet < & ' a Id > ,
19
20
}
20
21
@@ -29,7 +30,13 @@ fn set_remove<T: Hash + Eq + Clone>(set: &mut HashSet<T>) -> Option<T> {
29
30
30
31
impl < ' a > Validator < ' a > {
31
32
pub fn new ( krate : & ' a Crate ) -> Self {
32
- Self { krate, errs : Vec :: new ( ) , seen_ids : HashSet :: new ( ) , todo : HashSet :: new ( ) }
33
+ Self {
34
+ krate,
35
+ errs : Vec :: new ( ) ,
36
+ seen_ids : HashSet :: new ( ) ,
37
+ todo : HashSet :: new ( ) ,
38
+ missing_ids : HashSet :: new ( ) ,
39
+ }
33
40
}
34
41
35
42
pub fn check_crate ( & mut self ) {
@@ -42,32 +49,39 @@ impl<'a> Validator<'a> {
42
49
}
43
50
44
51
fn check_item ( & mut self , id : & ' a Id ) {
45
- let item = & self . krate . index [ id] ;
46
- match & item. inner {
47
- ItemEnum :: Import ( x) => self . check_import ( x) ,
48
- ItemEnum :: Union ( x) => self . check_union ( x) ,
49
- ItemEnum :: Struct ( x) => self . check_struct ( x) ,
50
- ItemEnum :: StructField ( x) => self . check_struct_field ( x) ,
51
- ItemEnum :: Enum ( x) => self . check_enum ( x) ,
52
- ItemEnum :: Variant ( x) => self . check_variant ( x) ,
53
- ItemEnum :: Function ( x) => self . check_function ( x) ,
54
- ItemEnum :: Trait ( x) => self . check_trait ( x) ,
55
- ItemEnum :: TraitAlias ( x) => self . check_trait_alias ( x) ,
56
- ItemEnum :: Method ( x) => self . check_method ( x) ,
57
- ItemEnum :: Impl ( x) => self . check_impl ( x) ,
58
- ItemEnum :: Typedef ( x) => self . check_typedef ( x) ,
59
- ItemEnum :: OpaqueTy ( x) => self . check_opaque_ty ( x) ,
60
- ItemEnum :: Constant ( x) => self . check_constant ( x) ,
61
- ItemEnum :: Static ( x) => self . check_static ( x) ,
62
- ItemEnum :: ForeignType => todo ! ( ) ,
63
- ItemEnum :: Macro ( x) => self . check_macro ( x) ,
64
- ItemEnum :: ProcMacro ( x) => self . check_proc_macro ( x) ,
65
- ItemEnum :: PrimitiveType ( x) => self . check_primitive_type ( x) ,
66
- ItemEnum :: Module ( x) => self . check_module ( x) ,
67
-
68
- ItemEnum :: ExternCrate { .. } => todo ! ( ) ,
69
- ItemEnum :: AssocConst { .. } => todo ! ( ) ,
70
- ItemEnum :: AssocType { .. } => todo ! ( ) ,
52
+ if let Some ( item) = & self . krate . index . get ( id) {
53
+ match & item. inner {
54
+ ItemEnum :: Import ( x) => self . check_import ( x) ,
55
+ ItemEnum :: Union ( x) => self . check_union ( x) ,
56
+ ItemEnum :: Struct ( x) => self . check_struct ( x) ,
57
+ ItemEnum :: StructField ( x) => self . check_struct_field ( x) ,
58
+ ItemEnum :: Enum ( x) => self . check_enum ( x) ,
59
+ ItemEnum :: Variant ( x) => self . check_variant ( x) ,
60
+ ItemEnum :: Function ( x) => self . check_function ( x) ,
61
+ ItemEnum :: Trait ( x) => self . check_trait ( x) ,
62
+ ItemEnum :: TraitAlias ( x) => self . check_trait_alias ( x) ,
63
+ ItemEnum :: Method ( x) => self . check_method ( x) ,
64
+ ItemEnum :: Impl ( x) => self . check_impl ( x) ,
65
+ ItemEnum :: Typedef ( x) => self . check_typedef ( x) ,
66
+ ItemEnum :: OpaqueTy ( x) => self . check_opaque_ty ( x) ,
67
+ ItemEnum :: Constant ( x) => self . check_constant ( x) ,
68
+ ItemEnum :: Static ( x) => self . check_static ( x) ,
69
+ ItemEnum :: ForeignType => todo ! ( ) ,
70
+ ItemEnum :: Macro ( x) => self . check_macro ( x) ,
71
+ ItemEnum :: ProcMacro ( x) => self . check_proc_macro ( x) ,
72
+ ItemEnum :: PrimitiveType ( x) => self . check_primitive_type ( x) ,
73
+ ItemEnum :: Module ( x) => self . check_module ( x) ,
74
+ // FIXME: Why don't these have their own structs?
75
+ ItemEnum :: ExternCrate { .. } => { }
76
+ ItemEnum :: AssocConst { type_, default : _ } => self . check_type ( type_) ,
77
+ ItemEnum :: AssocType { generics, bounds, default } => {
78
+ self . check_generics ( generics) ;
79
+ bounds. iter ( ) . for_each ( |b| self . check_generic_bound ( b) ) ;
80
+ if let Some ( ty) = default {
81
+ self . check_type ( ty) ;
82
+ }
83
+ }
84
+ }
71
85
}
72
86
}
73
87
@@ -226,7 +240,7 @@ impl<'a> Validator<'a> {
226
240
self . check_path ( trait_) ;
227
241
generic_params. iter ( ) . for_each ( |gpd| self . check_generic_param_def ( gpd) ) ;
228
242
}
229
- GenericBound :: Outlives ( _) => todo ! ( ) ,
243
+ GenericBound :: Outlives ( _) => { }
230
244
}
231
245
}
232
246
@@ -337,7 +351,10 @@ impl<'a> Validator<'a> {
337
351
self . fail_expecting ( id, expected) ;
338
352
}
339
353
} else {
340
- self . fail ( id, "Not found" )
354
+ if !self . missing_ids . contains ( id) {
355
+ self . missing_ids . insert ( id) ;
356
+ self . fail ( id, ErrorKind :: NotFound )
357
+ }
341
358
}
342
359
}
343
360
@@ -368,11 +385,11 @@ impl<'a> Validator<'a> {
368
385
369
386
fn fail_expecting ( & mut self , id : & Id , expected : & str ) {
370
387
let kind = self . kind_of ( id) . unwrap ( ) ; // We know it has a kind, as it's wrong.
371
- self . fail ( id, format ! ( "Expected {expected} but found {kind:?}" ) ) ;
388
+ self . fail ( id, ErrorKind :: Custom ( format ! ( "Expected {expected} but found {kind:?}" ) ) ) ;
372
389
}
373
390
374
- fn fail ( & mut self , id : & Id , message : impl Into < String > ) {
375
- self . errs . push ( Error { id : id. clone ( ) , message : message . into ( ) } ) ;
391
+ fn fail ( & mut self , id : & Id , kind : ErrorKind ) {
392
+ self . errs . push ( Error { id : id. clone ( ) , kind } ) ;
376
393
}
377
394
378
395
fn kind_of ( & mut self , id : & Id ) -> Option < Kind > {
0 commit comments