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