about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-12-06 13:27:43 +0100
committerGitHub <noreply@github.com>2022-12-06 13:27:43 +0100
commit61189b6ae3c5ccc8a38be18aad7ef75c253d7c28 (patch)
tree8e9023d7c59d97d11788747ef7c9e4651b8cfc7e /compiler
parent0a07ffe4ad8f29e22a237cad8099401faf3995b4 (diff)
parentf4c76b193d54eeb88b2c966612679d733536efaf (diff)
downloadrust-61189b6ae3c5ccc8a38be18aad7ef75c253d7c28.tar.gz
rust-61189b6ae3c5ccc8a38be18aad7ef75c253d7c28.zip
Rollup merge of #105310 - compiler-errors:issue-105288, r=eholk
Be more careful about unresolved exprs in suggestion

Fixes #105288
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/method/suggest.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs
index 9ba4ddfd5cf..db93cfab2c0 100644
--- a/compiler/rustc_hir_typeck/src/method/suggest.rs
+++ b/compiler/rustc_hir_typeck/src/method/suggest.rs
@@ -1482,15 +1482,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             ident_name: Symbol,
         }
 
+        // FIXME: This really should be taking scoping, etc into account.
         impl<'v> Visitor<'v> for LetVisitor<'v> {
             fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) {
-                if let hir::StmtKind::Local(hir::Local { pat, init, .. }) = &ex.kind {
-                    if let Binding(_, _, ident, ..) = pat.kind &&
-                        ident.name == self.ident_name {
-                        self.result = *init;
-                    }
+                if let hir::StmtKind::Local(hir::Local { pat, init, .. }) = &ex.kind
+                    && let Binding(_, _, ident, ..) = pat.kind
+                    && ident.name == self.ident_name
+                {
+                    self.result = *init;
+                } else {
+                    hir::intravisit::walk_stmt(self, ex);
                 }
-                hir::intravisit::walk_stmt(self, ex);
             }
         }
 
@@ -1498,9 +1500,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         visitor.visit_body(&body);
 
         let parent = self.tcx.hir().get_parent_node(seg1.hir_id);
-        if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) &&
-            let Some(expr) = visitor.result {
-            let self_ty = self.node_ty(expr.hir_id);
+        if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent)
+            && let Some(expr) = visitor.result
+            && let Some(self_ty) = self.node_ty_opt(expr.hir_id)
+        {
             let probe = self.lookup_probe(
                 seg2.ident,
                 self_ty,
@@ -1513,7 +1516,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     sm.span_extend_while(seg1.ident.span.shrink_to_hi(), |c| c == ':').unwrap(),
                     "you may have meant to call an instance method",
                     ".".to_string(),
-                    Applicability::MaybeIncorrect
+                    Applicability::MaybeIncorrect,
                 );
             }
         }