aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJacob Pratt <[email protected]>2021-01-10 08:05:52 +0000
committerJacob Pratt <[email protected]>2021-01-10 08:05:52 +0000
commit22566ecd1b3f64c0b5d577ea3dac161ebb23eda4 (patch)
tree0d9360a0ddb67bbea901a84f25c7600f3cc683c8 /crates
parentbd8a9035481ff2c349a36471c8c7c3533c3385c3 (diff)
Short-circuit boolean operation
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/inlay_hints.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index ddab9a168..2ad8c33f2 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -354,17 +354,21 @@ fn is_argument_similar_to_param_name(
354 match get_string_representation(argument) { 354 match get_string_representation(argument) {
355 None => false, 355 None => false,
356 Some(argument_string) => { 356 Some(argument_string) => {
357 // Does the argument name begin with the parameter name? Ignore leading underscores.
357 let mut arg_bytes = argument_string.bytes().skip_while(|&c| c == b'_'); 358 let mut arg_bytes = argument_string.bytes().skip_while(|&c| c == b'_');
358 let starts_with_pattern = param_name.bytes().all( 359 let starts_with_pattern = param_name.bytes().all(
359 |expected| matches!(arg_bytes.next(), Some(actual) if expected.eq_ignore_ascii_case(&actual)), 360 |expected| matches!(arg_bytes.next(), Some(actual) if expected.eq_ignore_ascii_case(&actual)),
360 ); 361 );
361 362
363 if starts_with_pattern {
364 return true;
365 }
366
367 // Does the argument name end with the parameter name?
362 let mut arg_bytes = argument_string.bytes(); 368 let mut arg_bytes = argument_string.bytes();
363 let ends_with_pattern = param_name.bytes().rev().all( 369 param_name.bytes().rev().all(
364 |expected| matches!(arg_bytes.next_back(), Some(actual) if expected.eq_ignore_ascii_case(&actual)), 370 |expected| matches!(arg_bytes.next_back(), Some(actual) if expected.eq_ignore_ascii_case(&actual)),
365 ); 371 )
366
367 starts_with_pattern || ends_with_pattern
368 } 372 }
369 } 373 }
370} 374}