]> git.lizzy.rs Git - rust.git/commitdiff
Short-circuit boolean operation
authorJacob Pratt <jacob@jhpratt.dev>
Sun, 10 Jan 2021 08:05:52 +0000 (03:05 -0500)
committerJacob Pratt <jacob@jhpratt.dev>
Sun, 10 Jan 2021 08:05:52 +0000 (03:05 -0500)
crates/ide/src/inlay_hints.rs

index ddab9a168a7581f2df0f80d0a8cc445d33f9e0e5..2ad8c33f204fc62e907c2b254d6e933c0cbba0c2 100644 (file)
@@ -354,17 +354,21 @@ fn is_argument_similar_to_param_name(
     match get_string_representation(argument) {
         None => false,
         Some(argument_string) => {
+            // Does the argument name begin with the parameter name? Ignore leading underscores.
             let mut arg_bytes = argument_string.bytes().skip_while(|&c| c == b'_');
             let starts_with_pattern = param_name.bytes().all(
                 |expected| matches!(arg_bytes.next(), Some(actual) if expected.eq_ignore_ascii_case(&actual)),
             );
 
+            if starts_with_pattern {
+                return true;
+            }
+
+            // Does the argument name end with the parameter name?
             let mut arg_bytes = argument_string.bytes();
-            let ends_with_pattern = param_name.bytes().rev().all(
+            param_name.bytes().rev().all(
                 |expected| matches!(arg_bytes.next_back(), Some(actual) if expected.eq_ignore_ascii_case(&actual)),
-            );
-
-            starts_with_pattern || ends_with_pattern
+            )
         }
     }
 }