@@ -8,13 +8,14 @@ use rustdoc_json_types::{
88 TypeBindingKind , Typedef , Union , Variant , WherePredicate ,
99} ;
1010
11- use crate :: { item_kind:: Kind , Error } ;
11+ use crate :: { item_kind:: Kind , Error , ErrorKind } ;
1212
1313#[ derive( Debug ) ]
1414pub struct Validator < ' a > {
1515 pub ( crate ) errs : Vec < Error > ,
1616 krate : & ' a Crate ,
1717 seen_ids : HashSet < & ' a Id > ,
18+ missing_ids : HashSet < & ' a Id > ,
1819 todo : HashSet < & ' a Id > ,
1920}
2021
@@ -29,7 +30,13 @@ fn set_remove<T: Hash + Eq + Clone>(set: &mut HashSet<T>) -> Option<T> {
2930
3031impl < ' a > Validator < ' a > {
3132 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+ }
3340 }
3441
3542 pub fn check_crate ( & mut self ) {
@@ -42,32 +49,39 @@ impl<'a> Validator<'a> {
4249 }
4350
4451 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+ }
7185 }
7286 }
7387
@@ -226,7 +240,7 @@ impl<'a> Validator<'a> {
226240 self . check_path ( trait_) ;
227241 generic_params. iter ( ) . for_each ( |gpd| self . check_generic_param_def ( gpd) ) ;
228242 }
229- GenericBound :: Outlives ( _) => todo ! ( ) ,
243+ GenericBound :: Outlives ( _) => { }
230244 }
231245 }
232246
@@ -337,7 +351,10 @@ impl<'a> Validator<'a> {
337351 self . fail_expecting ( id, expected) ;
338352 }
339353 } 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+ }
341358 }
342359 }
343360
@@ -368,11 +385,11 @@ impl<'a> Validator<'a> {
368385
369386 fn fail_expecting ( & mut self , id : & Id , expected : & str ) {
370387 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:?}" ) ) ) ;
372389 }
373390
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 } ) ;
376393 }
377394
378395 fn kind_of ( & mut self , id : & Id ) -> Option < Kind > {
0 commit comments