aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLúcás Meier <[email protected]>2019-10-04 07:21:24 +0100
committerLúcás Meier <[email protected]>2019-10-04 07:21:24 +0100
commit1ed1e3d4a757b8f57cb7c727d66703713cdc0bdf (patch)
treea712373088abbdf04b2c573bbe8c5f3b44ce8bd8
parente769a54502648011ede7d7434e0a16a8ab740c56 (diff)
Fix formatting
-rw-r--r--crates/ra_assists/src/assists/apply_demorgan.rs31
1 files changed, 9 insertions, 22 deletions
diff --git a/crates/ra_assists/src/assists/apply_demorgan.rs b/crates/ra_assists/src/assists/apply_demorgan.rs
index e4a8657ca..caecc50cc 100644
--- a/crates/ra_assists/src/assists/apply_demorgan.rs
+++ b/crates/ra_assists/src/assists/apply_demorgan.rs
@@ -2,8 +2,8 @@
2//! This assist transforms boolean expressions of the form `!a || !b` into 2//! This assist transforms boolean expressions of the form `!a || !b` into
3//! `!(a && b)`. 3//! `!(a && b)`.
4use hir::db::HirDatabase; 4use hir::db::HirDatabase;
5use ra_syntax::SyntaxNode;
6use ra_syntax::ast::{AstNode, BinExpr, BinOp, Expr, PrefixOp}; 5use ra_syntax::ast::{AstNode, BinExpr, BinOp, Expr, PrefixOp};
6use ra_syntax::SyntaxNode;
7 7
8use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
9 9
@@ -25,16 +25,16 @@ fn undo_negation(node: SyntaxNode) -> Option<String> {
25 let rhs = bin.rhs()?.syntax().text(); 25 let rhs = bin.rhs()?.syntax().text();
26 Some(format!("{} == {}", lhs, rhs)) 26 Some(format!("{} == {}", lhs, rhs))
27 } 27 }
28 _ => None 28 _ => None,
29 } 29 },
30 Expr::PrefixExpr(pe) => match pe.op_kind()? { 30 Expr::PrefixExpr(pe) => match pe.op_kind()? {
31 PrefixOp::Not => { 31 PrefixOp::Not => {
32 let child = pe.expr()?.syntax().text(); 32 let child = pe.expr()?.syntax().text();
33 Some(String::from(child)) 33 Some(String::from(child))
34 } 34 }
35 _ => None 35 _ => None,
36 } 36 },
37 _ => None 37 _ => None,
38 } 38 }
39} 39}
40 40
@@ -60,7 +60,6 @@ pub(crate) fn apply_demorgan(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Ass
60 let not_lhs = undo_negation(lhs)?; 60 let not_lhs = undo_negation(lhs)?;
61 let not_rhs = undo_negation(rhs)?; 61 let not_rhs = undo_negation(rhs)?;
62 62
63
64 ctx.add_action(AssistId("apply_demorgan"), "apply demorgan's law", |edit| { 63 ctx.add_action(AssistId("apply_demorgan"), "apply demorgan's law", |edit| {
65 edit.target(op_range); 64 edit.target(op_range);
66 edit.replace(op_range, opposite_op); 65 edit.replace(op_range, opposite_op);
@@ -78,29 +77,17 @@ mod tests {
78 77
79 #[test] 78 #[test]
80 fn demorgan_turns_and_into_or() { 79 fn demorgan_turns_and_into_or() {
81 check_assist( 80 check_assist(apply_demorgan, "fn f() { !x &&<|> !x }", "fn f() { !(x ||<|> x) }")
82 apply_demorgan,
83 "fn f() { !x &&<|> !x }",
84 "fn f() { !(x ||<|> x) }"
85 )
86 } 81 }
87 82
88 #[test] 83 #[test]
89 fn demorgan_turns_or_into_and() { 84 fn demorgan_turns_or_into_and() {
90 check_assist( 85 check_assist(apply_demorgan, "fn f() { !x ||<|> !x }", "fn f() { !(x &&<|> x) }")
91 apply_demorgan,
92 "fn f() { !x ||<|> !x }",
93 "fn f() { !(x &&<|> x) }"
94 )
95 } 86 }
96 87
97 #[test] 88 #[test]
98 fn demorgan_removes_inequality() { 89 fn demorgan_removes_inequality() {
99 check_assist( 90 check_assist(apply_demorgan, "fn f() { x != x ||<|> !x }", "fn f() { !(x == x &&<|> x) }")
100 apply_demorgan,
101 "fn f() { x != x ||<|> !x }",
102 "fn f() { !(x == x &&<|> x) }"
103 )
104 } 91 }
105 92
106 #[test] 93 #[test]