@@ -30,6 +30,11 @@ pub struct Validator<'a> {
30
30
missing_ids : HashSet < & ' a Id > ,
31
31
}
32
32
33
+ enum PathKind {
34
+ Trait ,
35
+ StructEnumUnion ,
36
+ }
37
+
33
38
impl < ' a > Validator < ' a > {
34
39
pub fn new ( krate : & ' a Crate ) -> Self {
35
40
Self {
@@ -165,7 +170,7 @@ impl<'a> Validator<'a> {
165
170
fn check_impl ( & mut self , x : & ' a Impl ) {
166
171
self . check_generics ( & x. generics ) ;
167
172
if let Some ( path) = & x. trait_ {
168
- self . check_path ( path) ; // TODO: Check is trait.
173
+ self . check_path ( path, PathKind :: Trait ) ;
169
174
}
170
175
self . check_type ( & x. for_ ) ;
171
176
x. items . iter ( ) . for_each ( |i| self . add_trait_item_id ( i) ) ;
@@ -211,7 +216,7 @@ impl<'a> Validator<'a> {
211
216
212
217
fn check_type ( & mut self , x : & ' a Type ) {
213
218
match x {
214
- Type :: ResolvedPath ( path) => self . check_path ( path) ,
219
+ Type :: ResolvedPath ( path) => self . check_path ( path, PathKind :: StructEnumUnion ) ,
215
220
Type :: DynTrait ( dyn_trait) => self . check_dyn_trait ( dyn_trait) ,
216
221
Type :: Generic ( _) => { }
217
222
Type :: Primitive ( _) => { }
@@ -226,7 +231,7 @@ impl<'a> Validator<'a> {
226
231
Type :: QualifiedPath { name : _, args, self_type, trait_ } => {
227
232
self . check_generic_args ( & * * args) ;
228
233
self . check_type ( & * * self_type) ;
229
- self . check_path ( trait_) ;
234
+ self . check_path ( trait_, PathKind :: Trait ) ;
230
235
}
231
236
}
232
237
}
@@ -241,15 +246,18 @@ impl<'a> Validator<'a> {
241
246
fn check_generic_bound ( & mut self , x : & ' a GenericBound ) {
242
247
match x {
243
248
GenericBound :: TraitBound { trait_, generic_params, modifier : _ } => {
244
- self . check_path ( trait_) ;
249
+ self . check_path ( trait_, PathKind :: Trait ) ;
245
250
generic_params. iter ( ) . for_each ( |gpd| self . check_generic_param_def ( gpd) ) ;
246
251
}
247
252
GenericBound :: Outlives ( _) => { }
248
253
}
249
254
}
250
255
251
- fn check_path ( & mut self , x : & ' a Path ) {
252
- self . add_id ( & x. id ) ; // TODO: What kinds are allowed here.
256
+ fn check_path ( & mut self , x : & ' a Path , kind : PathKind ) {
257
+ match kind {
258
+ PathKind :: Trait => self . add_trait_id ( & x. id ) ,
259
+ PathKind :: StructEnumUnion => self . add_struct_enum_union_id ( & x. id ) ,
260
+ }
253
261
if let Some ( args) = & x. args {
254
262
self . check_generic_args ( & * * args) ;
255
263
}
@@ -330,7 +338,7 @@ impl<'a> Validator<'a> {
330
338
331
339
fn check_dyn_trait ( & mut self , dyn_trait : & ' a DynTrait ) {
332
340
for pt in & dyn_trait. traits {
333
- self . check_path ( & pt. trait_ ) ;
341
+ self . check_path ( & pt. trait_ , PathKind :: Trait ) ;
334
342
pt. generic_params . iter ( ) . for_each ( |gpd| self . check_generic_param_def ( gpd) ) ;
335
343
}
336
344
}
@@ -340,13 +348,6 @@ impl<'a> Validator<'a> {
340
348
fp. generic_params . iter ( ) . for_each ( |gpd| self . check_generic_param_def ( gpd) ) ;
341
349
}
342
350
343
- // TODO: Remove
344
- fn add_id ( & mut self , id : & ' a Id ) {
345
- if !self . seen_ids . contains ( id) {
346
- self . todo . insert ( id) ;
347
- }
348
- }
349
-
350
351
fn add_id_checked ( & mut self , id : & ' a Id , valid : fn ( Kind ) -> bool , expected : & str ) {
351
352
if let Some ( kind) = self . kind_of ( id) {
352
353
if valid ( kind) {
@@ -379,6 +380,14 @@ impl<'a> Validator<'a> {
379
380
self . add_id_checked ( id, Kind :: is_variant, "Variant" ) ;
380
381
}
381
382
383
+ fn add_trait_id ( & mut self , id : & ' a Id ) {
384
+ self . add_id_checked ( id, Kind :: is_trait, "Trait" ) ;
385
+ }
386
+
387
+ fn add_struct_enum_union_id ( & mut self , id : & ' a Id ) {
388
+ self . add_id_checked ( id, Kind :: is_struct_enum_union, "Struct or Enum or Union" ) ;
389
+ }
390
+
382
391
/// Add an Id that appeared in a trait
383
392
fn add_trait_item_id ( & mut self , id : & ' a Id ) {
384
393
self . add_id_checked ( id, Kind :: can_appear_in_trait, "Trait inner item" ) ;
0 commit comments