aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_ty/src/diagnostics/decl_check/str_helpers.rs4
-rw-r--r--crates/stdx/src/lib.rs2
2 files changed, 3 insertions, 3 deletions
diff --git a/crates/hir_ty/src/diagnostics/decl_check/str_helpers.rs b/crates/hir_ty/src/diagnostics/decl_check/str_helpers.rs
index 8f70c5e84..c1ab1a675 100644
--- a/crates/hir_ty/src/diagnostics/decl_check/str_helpers.rs
+++ b/crates/hir_ty/src/diagnostics/decl_check/str_helpers.rs
@@ -13,7 +13,7 @@ enum DetectedCase {
13fn detect_case(ident: &str) -> DetectedCase { 13fn detect_case(ident: &str) -> DetectedCase {
14 let trimmed_ident = ident.trim_matches('_'); 14 let trimmed_ident = ident.trim_matches('_');
15 let first_lowercase = 15 let first_lowercase =
16 trimmed_ident.chars().next().map(|chr| chr.is_ascii_lowercase()).unwrap_or(false); 16 trimmed_ident.starts_with(|chr| chr.is_ascii_lowercase());
17 let mut has_lowercase = first_lowercase; 17 let mut has_lowercase = first_lowercase;
18 let mut has_uppercase = false; 18 let mut has_uppercase = false;
19 let mut has_underscore = false; 19 let mut has_underscore = false;
@@ -102,7 +102,7 @@ pub fn to_camel_case(ident: &str) -> Option<String> {
102} 102}
103 103
104/// Converts an identifier to a lower_snake_case form. 104/// Converts an identifier to a lower_snake_case form.
105/// Returns `None` if the string is already is lower_snake_case. 105/// Returns `None` if the string is already in lower_snake_case.
106pub fn to_lower_snake_case(ident: &str) -> Option<String> { 106pub fn to_lower_snake_case(ident: &str) -> Option<String> {
107 // First, assume that it's UPPER_SNAKE_CASE. 107 // First, assume that it's UPPER_SNAKE_CASE.
108 match detect_case(ident) { 108 match detect_case(ident) {
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 522a9c1ab..b55de813e 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -35,7 +35,7 @@ pub fn to_lower_snake_case(s: &str) -> String {
35 // `&& prev` is required to not insert `_` before the first symbol. 35 // `&& prev` is required to not insert `_` before the first symbol.
36 if c.is_ascii_uppercase() && prev { 36 if c.is_ascii_uppercase() && prev {
37 // This check is required to not translate `Weird_Case` into `weird__case`. 37 // This check is required to not translate `Weird_Case` into `weird__case`.
38 if buf.chars().last() != Some('_') { 38 if !buf.ends_with('_') {
39 buf.push('_') 39 buf.push('_')
40 } 40 }
41 } 41 }