Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c1c8675

Browse files
committed
Add Expr::Underscore
1 parent e107995 commit c1c8675

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

crates/hir-def/src/body/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ impl ExprCollector<'_> {
536536

537537
self.alloc_expr(Expr::MacroStmts { tail }, syntax_ptr)
538538
}
539-
ast::Expr::UnderscoreExpr(_) => return None,
539+
ast::Expr::UnderscoreExpr(_) => self.alloc_expr(Expr::Underscore, syntax_ptr),
540540
})
541541
}
542542

crates/hir-def/src/expr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ pub enum Expr {
203203
},
204204
Array(Array),
205205
Literal(Literal),
206+
Underscore,
206207
}
207208

208209
#[derive(Debug, Clone, Eq, PartialEq)]
@@ -345,6 +346,7 @@ impl Expr {
345346
},
346347
Expr::MacroStmts { tail } => f(*tail),
347348
Expr::Literal(_) => {}
349+
Expr::Underscore => {}
348350
}
349351
}
350352
}

crates/hir-ty/src/infer/expr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,12 @@ impl<'a> InferenceContext<'a> {
775775
},
776776
},
777777
Expr::MacroStmts { tail } => self.infer_expr_inner(*tail, expected),
778+
Expr::Underscore => {
779+
// Underscore expressions may only appear in assignee expressions,
780+
// which are handled by `infer_assignee_expr()`, so any underscore
781+
// expression reaching this branch is an error.
782+
self.err_ty()
783+
}
778784
};
779785
// use a new type variable if we got unknown here
780786
let ty = self.insert_type_vars_shallow(ty);

0 commit comments

Comments
 (0)