mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Touch up type inference for boolean operators
Also try to infer its subexpressions and set type expectations whenever possible.
This commit is contained in:
parent
4fc233a02e
commit
82d9a77dad
6 changed files with 93 additions and 43 deletions
|
@ -511,20 +511,33 @@ impl<'a> BinExpr<'a> {
|
|||
pub fn op(&self) -> Option<BinOp> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(|c| {
|
||||
match c.kind() {
|
||||
PIPEPIPE => Some(BinOp::BooleanOr),
|
||||
AMPAMP => Some(BinOp::BooleanAnd),
|
||||
EQEQ => Some(BinOp::EqualityTest),
|
||||
LTEQ => Some(BinOp::LesserEqualTest),
|
||||
GTEQ => Some(BinOp::GreaterEqualTest),
|
||||
L_ANGLE => Some(BinOp::LesserTest),
|
||||
R_ANGLE => Some(BinOp::GreaterTest),
|
||||
_ => None,
|
||||
}
|
||||
.filter_map(|c| match c.kind() {
|
||||
PIPEPIPE => Some(BinOp::BooleanOr),
|
||||
AMPAMP => Some(BinOp::BooleanAnd),
|
||||
EQEQ => Some(BinOp::EqualityTest),
|
||||
LTEQ => Some(BinOp::LesserEqualTest),
|
||||
GTEQ => Some(BinOp::GreaterEqualTest),
|
||||
L_ANGLE => Some(BinOp::LesserTest),
|
||||
R_ANGLE => Some(BinOp::GreaterTest),
|
||||
_ => None,
|
||||
})
|
||||
.next()
|
||||
}
|
||||
|
||||
pub fn lhs(self) -> Option<Expr<'a>> {
|
||||
children(self).nth(0)
|
||||
}
|
||||
|
||||
pub fn rhs(self) -> Option<Expr<'a>> {
|
||||
children(self).nth(1)
|
||||
}
|
||||
|
||||
pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) {
|
||||
let mut children = children(self);
|
||||
let first = children.next();
|
||||
let second = children.next();
|
||||
(first, second)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue