@@ -71,6 +71,19 @@ impl<'a> Validator<'a> {
71
71
}
72
72
}
73
73
74
+ fn check_items ( & mut self , id : & Id , items : & [ Id ] ) {
75
+ let mut visited_ids = HashSet :: with_capacity ( items. len ( ) ) ;
76
+
77
+ for item in items {
78
+ if !visited_ids. insert ( item) {
79
+ self . fail (
80
+ id,
81
+ ErrorKind :: Custom ( format ! ( "Duplicated entry in `items` field: `{item:?}`" ) ) ,
82
+ ) ;
83
+ }
84
+ }
85
+ }
86
+
74
87
fn check_item ( & mut self , id : & ' a Id ) {
75
88
if let Some ( item) = & self . krate . index . get ( id) {
76
89
item. links . values ( ) . for_each ( |id| self . add_any_id ( id) ) ;
@@ -83,9 +96,9 @@ impl<'a> Validator<'a> {
83
96
ItemEnum :: Enum ( x) => self . check_enum ( x) ,
84
97
ItemEnum :: Variant ( x) => self . check_variant ( x, id) ,
85
98
ItemEnum :: Function ( x) => self . check_function ( x) ,
86
- ItemEnum :: Trait ( x) => self . check_trait ( x) ,
99
+ ItemEnum :: Trait ( x) => self . check_trait ( x, id ) ,
87
100
ItemEnum :: TraitAlias ( x) => self . check_trait_alias ( x) ,
88
- ItemEnum :: Impl ( x) => self . check_impl ( x) ,
101
+ ItemEnum :: Impl ( x) => self . check_impl ( x, id ) ,
89
102
ItemEnum :: Typedef ( x) => self . check_typedef ( x) ,
90
103
ItemEnum :: OpaqueTy ( x) => self . check_opaque_ty ( x) ,
91
104
ItemEnum :: Constant ( x) => self . check_constant ( x) ,
@@ -94,7 +107,7 @@ impl<'a> Validator<'a> {
94
107
ItemEnum :: Macro ( x) => self . check_macro ( x) ,
95
108
ItemEnum :: ProcMacro ( x) => self . check_proc_macro ( x) ,
96
109
ItemEnum :: Primitive ( x) => self . check_primitive_type ( x) ,
97
- ItemEnum :: Module ( x) => self . check_module ( x) ,
110
+ ItemEnum :: Module ( x) => self . check_module ( x, id ) ,
98
111
// FIXME: Why don't these have their own structs?
99
112
ItemEnum :: ExternCrate { .. } => { }
100
113
ItemEnum :: AssocConst { type_, default : _ } => self . check_type ( type_) ,
@@ -112,7 +125,8 @@ impl<'a> Validator<'a> {
112
125
}
113
126
114
127
// Core checkers
115
- fn check_module ( & mut self , module : & ' a Module ) {
128
+ fn check_module ( & mut self , module : & ' a Module , id : & Id ) {
129
+ self . check_items ( id, & module. items ) ;
116
130
module. items . iter ( ) . for_each ( |i| self . add_mod_item_id ( i) ) ;
117
131
}
118
132
@@ -181,7 +195,8 @@ impl<'a> Validator<'a> {
181
195
self . check_fn_decl ( & x. decl ) ;
182
196
}
183
197
184
- fn check_trait ( & mut self , x : & ' a Trait ) {
198
+ fn check_trait ( & mut self , x : & ' a Trait , id : & Id ) {
199
+ self . check_items ( id, & x. items ) ;
185
200
self . check_generics ( & x. generics ) ;
186
201
x. items . iter ( ) . for_each ( |i| self . add_trait_item_id ( i) ) ;
187
202
x. bounds . iter ( ) . for_each ( |i| self . check_generic_bound ( i) ) ;
@@ -193,7 +208,8 @@ impl<'a> Validator<'a> {
193
208
x. params . iter ( ) . for_each ( |i| self . check_generic_bound ( i) ) ;
194
209
}
195
210
196
- fn check_impl ( & mut self , x : & ' a Impl ) {
211
+ fn check_impl ( & mut self , x : & ' a Impl , id : & Id ) {
212
+ self . check_items ( id, & x. items ) ;
197
213
self . check_generics ( & x. generics ) ;
198
214
if let Some ( path) = & x. trait_ {
199
215
self . check_path ( path, PathKind :: Trait ) ;
0 commit comments