about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/hir-def/src/body/lower.rs2
-rw-r--r--crates/hir-def/src/expr.rs2
-rw-r--r--crates/hir-ty/src/infer/expr.rs6
3 files changed, 9 insertions, 1 deletions
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs
index 5d7a1100cd5..cf20ad7139b 100644
--- a/crates/hir-def/src/body/lower.rs
+++ b/crates/hir-def/src/body/lower.rs
@@ -536,7 +536,7 @@ impl ExprCollector<'_> {
 
                 self.alloc_expr(Expr::MacroStmts { tail }, syntax_ptr)
             }
-            ast::Expr::UnderscoreExpr(_) => return None,
+            ast::Expr::UnderscoreExpr(_) => self.alloc_expr(Expr::Underscore, syntax_ptr),
         })
     }
 
diff --git a/crates/hir-def/src/expr.rs b/crates/hir-def/src/expr.rs
index bc060858946..49b7ef451ed 100644
--- a/crates/hir-def/src/expr.rs
+++ b/crates/hir-def/src/expr.rs
@@ -203,6 +203,7 @@ pub enum Expr {
     },
     Array(Array),
     Literal(Literal),
+    Underscore,
 }
 
 #[derive(Debug, Clone, Eq, PartialEq)]
@@ -345,6 +346,7 @@ impl Expr {
             },
             Expr::MacroStmts { tail } => f(*tail),
             Expr::Literal(_) => {}
+            Expr::Underscore => {}
         }
     }
 }
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index 2e645bf52ba..4d4d187fe8a 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -775,6 +775,12 @@ impl<'a> InferenceContext<'a> {
                 },
             },
             Expr::MacroStmts { tail } => self.infer_expr_inner(*tail, expected),
+            Expr::Underscore => {
+                // Underscore expressions may only appear in assignee expressions,
+                // which are handled by `infer_assignee_expr()`, so any underscore
+                // expression reaching this branch is an error.
+                self.err_ty()
+            }
         };
         // use a new type variable if we got unknown here
         let ty = self.insert_type_vars_shallow(ty);