]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggestions from code review
authorIgor Aleksanov <popzxc@yandex.ru>
Mon, 5 Oct 2020 16:34:23 +0000 (19:34 +0300)
committerIgor Aleksanov <popzxc@yandex.ru>
Mon, 12 Oct 2020 08:05:00 +0000 (11:05 +0300)
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
crates/hir_ty/src/diagnostics/decl_check/str_helpers.rs
crates/stdx/src/lib.rs

index 8f70c5e846dae5ce390ff330e5778e98e776298b..c1ab1a675933dae48f39c1c00a9526cabf792b0a 100644 (file)
@@ -13,7 +13,7 @@ enum DetectedCase {
 fn detect_case(ident: &str) -> DetectedCase {
     let trimmed_ident = ident.trim_matches('_');
     let first_lowercase =
-        trimmed_ident.chars().next().map(|chr| chr.is_ascii_lowercase()).unwrap_or(false);
+        trimmed_ident.starts_with(|chr| chr.is_ascii_lowercase());
     let mut has_lowercase = first_lowercase;
     let mut has_uppercase = false;
     let mut has_underscore = false;
@@ -102,7 +102,7 @@ pub fn to_camel_case(ident: &str) -> Option<String> {
 }
 
 /// Converts an identifier to a lower_snake_case form.
-/// Returns `None` if the string is already is lower_snake_case.
+/// Returns `None` if the string is already in lower_snake_case.
 pub fn to_lower_snake_case(ident: &str) -> Option<String> {
     // First, assume that it's UPPER_SNAKE_CASE.
     match detect_case(ident) {
index 522a9c1abdf385b5df0ead8a42373d303d016856..b55de813ec521e1a7be9b301db4355d5bb853e3a 100644 (file)
@@ -35,7 +35,7 @@ pub fn to_lower_snake_case(s: &str) -> String {
         // `&& prev` is required to not insert `_` before the first symbol.
         if c.is_ascii_uppercase() && prev {
             // This check is required to not translate `Weird_Case` into `weird__case`.
-            if buf.chars().last() != Some('_') {
+            if !buf.ends_with('_') {
                 buf.push('_')
             }
         }