@@ -286,6 +286,58 @@ struct TyCheckerFinalizer<'db> {
286
286
diags : Vec < FuncBodyDiag < ' db > > ,
287
287
}
288
288
289
+ impl < ' db > Visitor < ' db > for TyCheckerFinalizer < ' db > {
290
+ fn visit_pat (
291
+ & mut self ,
292
+ ctxt : & mut VisitorCtxt < ' db , LazyPatSpan < ' db > > ,
293
+ pat : PatId ,
294
+ _: & Pat < ' db > ,
295
+ ) {
296
+ let ty = self . body . pat_ty ( self . db , pat) ;
297
+ let span = ctxt. span ( ) . unwrap ( ) ;
298
+ self . check_unknown ( ty, span. clone ( ) . into ( ) ) ;
299
+
300
+ walk_pat ( self , ctxt, pat)
301
+ }
302
+
303
+ fn visit_expr (
304
+ & mut self ,
305
+ ctxt : & mut VisitorCtxt < ' db , LazyExprSpan < ' db > > ,
306
+ expr : ExprId ,
307
+ expr_data : & Expr < ' db > ,
308
+ ) {
309
+ // Skip the check if the expr is block.
310
+ if !matches ! ( expr_data, Expr :: Block ( ..) ) {
311
+ let prop = self . body . expr_prop ( self . db , expr) ;
312
+ let span = ctxt. span ( ) . unwrap ( ) ;
313
+ self . check_unknown ( prop. ty , span. clone ( ) . into ( ) ) ;
314
+ if prop. binding . is_none ( ) {
315
+ self . check_wf ( prop. ty , span. into ( ) ) ;
316
+ }
317
+ }
318
+
319
+ // We need this additional check for method call because the callable type is
320
+ // not tied to the expression type.
321
+ if let Expr :: MethodCall ( ..) = expr_data {
322
+ if let Some ( callable) = self . body . callable_expr ( expr) {
323
+ let callable_ty = callable. ty ( self . db ) ;
324
+ let span = ctxt. span ( ) . unwrap ( ) . into_method_call_expr ( ) . method_name ( ) ;
325
+ self . check_unknown ( callable_ty, span. clone ( ) . into ( ) ) ;
326
+ self . check_wf ( callable_ty, span. into ( ) )
327
+ }
328
+ }
329
+
330
+ walk_expr ( self , ctxt, expr) ;
331
+ }
332
+
333
+ fn visit_item (
334
+ & mut self ,
335
+ _: & mut VisitorCtxt < ' db , hir:: visitor:: prelude:: LazyItemSpan < ' db > > ,
336
+ _: hir:: hir_def:: ItemKind < ' db > ,
337
+ ) {
338
+ }
339
+ }
340
+
289
341
impl < ' db > TyCheckerFinalizer < ' db > {
290
342
fn new ( mut checker : TyChecker < ' db > ) -> Self {
291
343
let assumptions = checker. env . assumptions ( ) ;
@@ -306,58 +358,6 @@ impl<'db> TyCheckerFinalizer<'db> {
306
358
}
307
359
308
360
fn check_unknown_types ( & mut self ) {
309
- impl < ' db > Visitor < ' db > for TyCheckerFinalizer < ' db > {
310
- fn visit_pat (
311
- & mut self ,
312
- ctxt : & mut VisitorCtxt < ' db , LazyPatSpan < ' db > > ,
313
- pat : PatId ,
314
- _: & Pat < ' db > ,
315
- ) {
316
- let ty = self . body . pat_ty ( self . db , pat) ;
317
- let span = ctxt. span ( ) . unwrap ( ) ;
318
- self . check_unknown ( ty, span. clone ( ) . into ( ) ) ;
319
-
320
- walk_pat ( self , ctxt, pat)
321
- }
322
-
323
- fn visit_expr (
324
- & mut self ,
325
- ctxt : & mut VisitorCtxt < ' db , LazyExprSpan < ' db > > ,
326
- expr : ExprId ,
327
- expr_data : & Expr < ' db > ,
328
- ) {
329
- // Skip the check if the expr is block.
330
- if !matches ! ( expr_data, Expr :: Block ( ..) ) {
331
- let prop = self . body . expr_prop ( self . db , expr) ;
332
- let span = ctxt. span ( ) . unwrap ( ) ;
333
- self . check_unknown ( prop. ty , span. clone ( ) . into ( ) ) ;
334
- if prop. binding . is_none ( ) {
335
- self . check_wf ( prop. ty , span. into ( ) ) ;
336
- }
337
- }
338
-
339
- // We need this additional check for method call because the callable type is
340
- // not tied to the expression type.
341
- if let Expr :: MethodCall ( ..) = expr_data {
342
- if let Some ( callable) = self . body . callable_expr ( expr) {
343
- let callable_ty = callable. ty ( self . db ) ;
344
- let span = ctxt. span ( ) . unwrap ( ) . into_method_call_expr ( ) . method_name ( ) ;
345
- self . check_unknown ( callable_ty, span. clone ( ) . into ( ) ) ;
346
- self . check_wf ( callable_ty, span. into ( ) )
347
- }
348
- }
349
-
350
- walk_expr ( self , ctxt, expr) ;
351
- }
352
-
353
- fn visit_item (
354
- & mut self ,
355
- _: & mut VisitorCtxt < ' db , hir:: visitor:: prelude:: LazyItemSpan < ' db > > ,
356
- _: hir:: hir_def:: ItemKind < ' db > ,
357
- ) {
358
- }
359
- }
360
-
361
361
if let Some ( body) = self . body . body {
362
362
let mut ctxt = VisitorCtxt :: with_body ( self . db . as_hir_db ( ) , body) ;
363
363
self . visit_body ( & mut ctxt, body) ;
0 commit comments