@@ -1482,25 +1482,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1482
1482
ident_name : Symbol ,
1483
1483
}
1484
1484
1485
+ // FIXME: This really should be taking scoping, etc into account.
1485
1486
impl < ' v > Visitor < ' v > for LetVisitor < ' v > {
1486
1487
fn visit_stmt ( & mut self , ex : & ' v hir:: Stmt < ' v > ) {
1487
- if let hir:: StmtKind :: Local ( hir:: Local { pat, init, .. } ) = & ex. kind {
1488
- if let Binding ( _, _, ident, ..) = pat. kind &&
1489
- ident. name == self . ident_name {
1490
- self . result = * init;
1491
- }
1488
+ if let hir:: StmtKind :: Local ( hir:: Local { pat, init, .. } ) = & ex. kind
1489
+ && let Binding ( _, _, ident, ..) = pat. kind
1490
+ && ident. name == self . ident_name
1491
+ {
1492
+ self . result = * init;
1493
+ } else {
1494
+ hir:: intravisit:: walk_stmt ( self , ex) ;
1492
1495
}
1493
- hir:: intravisit:: walk_stmt ( self , ex) ;
1494
1496
}
1495
1497
}
1496
1498
1497
1499
let mut visitor = LetVisitor { result : None , ident_name : seg1. ident . name } ;
1498
1500
visitor. visit_body ( & body) ;
1499
1501
1500
1502
let parent = self . tcx . hir ( ) . get_parent_node ( seg1. hir_id ) ;
1501
- if let Some ( Node :: Expr ( call_expr) ) = self . tcx . hir ( ) . find ( parent) &&
1502
- let Some ( expr) = visitor. result {
1503
- let self_ty = self . node_ty ( expr. hir_id ) ;
1503
+ if let Some ( Node :: Expr ( call_expr) ) = self . tcx . hir ( ) . find ( parent)
1504
+ && let Some ( expr) = visitor. result
1505
+ && let Some ( self_ty) = self . node_ty_opt ( expr. hir_id )
1506
+ {
1504
1507
let probe = self . lookup_probe (
1505
1508
seg2. ident ,
1506
1509
self_ty,
@@ -1513,7 +1516,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1513
1516
sm. span_extend_while ( seg1. ident . span . shrink_to_hi ( ) , |c| c == ':' ) . unwrap ( ) ,
1514
1517
"you may have meant to call an instance method" ,
1515
1518
"." . to_string ( ) ,
1516
- Applicability :: MaybeIncorrect
1519
+ Applicability :: MaybeIncorrect ,
1517
1520
) ;
1518
1521
}
1519
1522
}
0 commit comments