From f7a4a87de2840789e12722afc7df9f4db2db013c Mon Sep 17 00:00:00 2001 From: lbrande Date: Fri, 19 Feb 2021 14:48:07 +0100 Subject: De Morgan's Law assist now correctly parenthesizes binary expressions. --- crates/ide_assists/src/handlers/apply_demorgan.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ide_assists/src/handlers') diff --git a/crates/ide_assists/src/handlers/apply_demorgan.rs b/crates/ide_assists/src/handlers/apply_demorgan.rs index ed4d11455..e478ff2ce 100644 --- a/crates/ide_assists/src/handlers/apply_demorgan.rs +++ b/crates/ide_assists/src/handlers/apply_demorgan.rs @@ -7,18 +7,17 @@ use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKin // Apply https://en.wikipedia.org/wiki/De_Morgan%27s_laws[De Morgan's law]. // This transforms expressions of the form `!l || !r` into `!(l && r)`. // This also works with `&&`. This assist can only be applied with the cursor -// on either `||` or `&&`, with both operands being a negation of some kind. -// This means something of the form `!x` or `x != y`. +// on either `||` or `&&`. // // ``` // fn main() { -// if x != 4 ||$0 !y {} +// if x != 4 ||$0 y < 3 {} // } // ``` // -> // ``` // fn main() { -// if !(x == 4 && y) {} +// if !(x == 4 && !(y < 3)) {} // } // ``` pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { -- cgit v1.2.3