aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-04 20:59:57 +0000
committerGitHub <[email protected]>2020-01-04 20:59:57 +0000
commitfe00a34fcc82c6741c88c17badab1994cf62496e (patch)
tree75f478c3e67bcf97b92c4b73cbed1b85e82a2a94 /crates
parentc15293e0193008fb855ed49e8deb533dfaa3e9c7 (diff)
parent5afb22e2b383a2894297f3508cd3e954da96da1c (diff)
Merge #2747
2747: BinOp helper to detect assignment r=matklad a=kjeremy Co-authored-by: Jeremy Kolb <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assists/flip_binexpr.rs12
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs18
2 files changed, 19 insertions, 11 deletions
diff --git a/crates/ra_assists/src/assists/flip_binexpr.rs b/crates/ra_assists/src/assists/flip_binexpr.rs
index 386045eb0..2d91b2a7e 100644
--- a/crates/ra_assists/src/assists/flip_binexpr.rs
+++ b/crates/ra_assists/src/assists/flip_binexpr.rs
@@ -56,17 +56,7 @@ enum FlipAction {
56impl From<BinOp> for FlipAction { 56impl From<BinOp> for FlipAction {
57 fn from(op_kind: BinOp) -> Self { 57 fn from(op_kind: BinOp) -> Self {
58 match op_kind { 58 match op_kind {
59 BinOp::Assignment => FlipAction::DontFlip, 59 kind if kind.is_assignment() => FlipAction::DontFlip,
60 BinOp::AddAssign => FlipAction::DontFlip,
61 BinOp::DivAssign => FlipAction::DontFlip,
62 BinOp::MulAssign => FlipAction::DontFlip,
63 BinOp::RemAssign => FlipAction::DontFlip,
64 BinOp::ShrAssign => FlipAction::DontFlip,
65 BinOp::ShlAssign => FlipAction::DontFlip,
66 BinOp::SubAssign => FlipAction::DontFlip,
67 BinOp::BitOrAssign => FlipAction::DontFlip,
68 BinOp::BitAndAssign => FlipAction::DontFlip,
69 BinOp::BitXorAssign => FlipAction::DontFlip,
70 BinOp::GreaterTest => FlipAction::FlipAndReplaceOp("<"), 60 BinOp::GreaterTest => FlipAction::FlipAndReplaceOp("<"),
71 BinOp::GreaterEqualTest => FlipAction::FlipAndReplaceOp("<="), 61 BinOp::GreaterEqualTest => FlipAction::FlipAndReplaceOp("<="),
72 BinOp::LesserTest => FlipAction::FlipAndReplaceOp(">"), 62 BinOp::LesserTest => FlipAction::FlipAndReplaceOp(">"),
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 2fd039837..23b6aa901 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -126,6 +126,24 @@ pub enum BinOp {
126 BitXorAssign, 126 BitXorAssign,
127} 127}
128 128
129impl BinOp {
130 pub fn is_assignment(&self) -> bool {
131 match *self {
132 BinOp::Assignment
133 | BinOp::AddAssign
134 | BinOp::DivAssign
135 | BinOp::MulAssign
136 | BinOp::RemAssign
137 | BinOp::ShrAssign
138 | BinOp::ShlAssign
139 | BinOp::SubAssign
140 | BinOp::BitOrAssign
141 | BinOp::BitAndAssign
142 | BinOp::BitXorAssign => true,
143 _ => false,
144 }
145 }
146}
129impl ast::BinExpr { 147impl ast::BinExpr {
130 pub fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { 148 pub fn op_details(&self) -> Option<(SyntaxToken, BinOp)> {
131 self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| { 149 self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| {