Skip to content

Commit

Permalink
Add Expr::Underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
lowr committed May 31, 2022
1 parent e107995 commit c1c8675
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}

Expand Down
2 changes: 2 additions & 0 deletions crates/hir-def/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub enum Expr {
},
Array(Array),
Literal(Literal),
Underscore,
}

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -345,6 +346,7 @@ impl Expr {
},
Expr::MacroStmts { tail } => f(*tail),
Expr::Literal(_) => {}
Expr::Underscore => {}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/hir-ty/src/infer/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c1c8675

Please sign in to comment.