mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Implement type inference for boolean operators
This commit is contained in:
parent
3e42a15878
commit
4fc233a02e
6 changed files with 92 additions and 4 deletions
|
@ -488,6 +488,45 @@ impl<'a> PrefixExpr<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum BinOp {
|
||||
/// The `||` operator for boolean OR
|
||||
BooleanOr,
|
||||
/// The `&&` operator for boolean AND
|
||||
BooleanAnd,
|
||||
/// The `==` operator for equality testing
|
||||
EqualityTest,
|
||||
/// The `<=` operator for lesser-equal testing
|
||||
LesserEqualTest,
|
||||
/// The `>=` operator for greater-equal testing
|
||||
GreaterEqualTest,
|
||||
/// The `<` operator for comparison
|
||||
LesserTest,
|
||||
/// The `>` operator for comparison
|
||||
GreaterTest,
|
||||
// TODO: lots of others
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
})
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum SelfParamFlavor {
|
||||
/// self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue