@@ -99,35 +99,41 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypePass {
99
99
}
100
100
101
101
fn check_struct_field ( & mut self , cx : & LateContext , field : & StructField ) {
102
- check_ty ( cx, & field. ty ) ;
102
+ check_ty ( cx, & field. ty , false ) ;
103
103
}
104
104
105
105
fn check_trait_item ( & mut self , cx : & LateContext , item : & TraitItem ) {
106
106
match item. node {
107
107
TraitItemKind :: Const ( ref ty, _) |
108
- TraitItemKind :: Type ( _, Some ( ref ty) ) => check_ty ( cx, ty) ,
108
+ TraitItemKind :: Type ( _, Some ( ref ty) ) => check_ty ( cx, ty, false ) ,
109
109
TraitItemKind :: Method ( ref sig, _) => check_fn_decl ( cx, & sig. decl ) ,
110
110
_ => ( ) ,
111
111
}
112
112
}
113
+
114
+ fn check_local ( & mut self , cx : & LateContext , local : & Local ) {
115
+ if let Some ( ref ty) = local. ty {
116
+ check_ty ( cx, ty, true ) ;
117
+ }
118
+ }
113
119
}
114
120
115
121
fn check_fn_decl ( cx : & LateContext , decl : & FnDecl ) {
116
122
for input in & decl. inputs {
117
- check_ty ( cx, input) ;
123
+ check_ty ( cx, input, false ) ;
118
124
}
119
125
120
126
if let FunctionRetTy :: Return ( ref ty) = decl. output {
121
- check_ty ( cx, ty) ;
127
+ check_ty ( cx, ty, false ) ;
122
128
}
123
129
}
124
130
125
- fn check_ty ( cx : & LateContext , ast_ty : & Ty ) {
131
+ fn check_ty ( cx : & LateContext , ast_ty : & Ty , is_local : bool ) {
126
132
if in_macro ( ast_ty. span ) {
127
133
return ;
128
134
}
129
135
match ast_ty. node {
130
- TyPath ( ref qpath) => {
136
+ TyPath ( ref qpath) if !is_local => {
131
137
let def = cx. tables . qpath_def ( qpath, ast_ty. id ) ;
132
138
if let Some ( def_id) = opt_def_id ( def) {
133
139
if Some ( def_id) == cx. tcx . lang_items . owned_box ( ) {
@@ -158,20 +164,20 @@ fn check_ty(cx: &LateContext, ast_ty: &Ty) {
158
164
}
159
165
match * qpath {
160
166
QPath :: Resolved ( Some ( ref ty) , ref p) => {
161
- check_ty ( cx, ty) ;
167
+ check_ty ( cx, ty, is_local ) ;
162
168
for ty in p. segments . iter ( ) . flat_map ( |seg| seg. parameters . types ( ) ) {
163
- check_ty ( cx, ty) ;
169
+ check_ty ( cx, ty, is_local ) ;
164
170
}
165
171
} ,
166
172
QPath :: Resolved ( None , ref p) => {
167
173
for ty in p. segments . iter ( ) . flat_map ( |seg| seg. parameters . types ( ) ) {
168
- check_ty ( cx, ty) ;
174
+ check_ty ( cx, ty, is_local ) ;
169
175
}
170
176
} ,
171
177
QPath :: TypeRelative ( ref ty, ref seg) => {
172
- check_ty ( cx, ty) ;
178
+ check_ty ( cx, ty, is_local ) ;
173
179
for ty in seg. parameters . types ( ) {
174
- check_ty ( cx, ty) ;
180
+ check_ty ( cx, ty, is_local ) ;
175
181
}
176
182
} ,
177
183
}
@@ -212,18 +218,18 @@ fn check_ty(cx: &LateContext, ast_ty: &Ty) {
212
218
} } ;
213
219
}
214
220
}
215
- check_ty ( cx, ty) ;
221
+ check_ty ( cx, ty, is_local ) ;
216
222
} ,
217
- _ => check_ty ( cx, ty) ,
223
+ _ => check_ty ( cx, ty, is_local ) ,
218
224
}
219
225
} ,
220
226
// recurse
221
227
TySlice ( ref ty) |
222
228
TyArray ( ref ty, _) |
223
- TyPtr ( MutTy { ref ty, .. } ) => check_ty ( cx, ty) ,
229
+ TyPtr ( MutTy { ref ty, .. } ) => check_ty ( cx, ty, is_local ) ,
224
230
TyTup ( ref tys) => {
225
231
for ty in tys {
226
- check_ty ( cx, ty) ;
232
+ check_ty ( cx, ty, is_local ) ;
227
233
}
228
234
} ,
229
235
_ => { } ,
0 commit comments