]> git.lizzy.rs Git - rust.git/commitdiff
cleanups
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 9 May 2021 14:59:52 +0000 (17:59 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 9 May 2021 15:01:54 +0000 (18:01 +0300)
crates/ide_assists/src/handlers/extract_variable.rs
crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
crates/ide_assists/src/utils/suggest_name.rs

index 136b9a55b946c4604648c4accf93e184b9669e9a..ae084c86c2f57c624a1f65b99db6862aed3ae5fa 100644 (file)
@@ -54,7 +54,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
 
             let var_name = match &field_shorthand {
                 Some(it) => it.to_string(),
-                None => suggest_name::variable(&to_extract, &ctx.sema),
+                None => suggest_name::for_variable(&to_extract, &ctx.sema),
             };
             let expr_range = match &field_shorthand {
                 Some(it) => it.syntax().text_range().cover(to_extract.syntax().text_range()),
index 26a0e81f0eaba9d165d10e91ccb390f8a4f53b44..899c773df5a4234780ed878ce6e1f9f49e3f1368 100644 (file)
@@ -29,7 +29,7 @@ pub(crate) fn replace_impl_trait_with_generic(
         "Replace impl trait with generic",
         target,
         |edit| {
-            let type_param_name = suggest_name::generic_parameter(&impl_trait_type);
+            let type_param_name = suggest_name::for_generic_parameter(&impl_trait_type);
 
             let generic_param_list = fn_
                 .generic_param_list()
index c8487846d7ecb064ddd2de02472a12ced23a80b6..b3aabeab37adc77cd146275250ae3c0dbbacf229 100644 (file)
@@ -57,7 +57,7 @@
     "iter_mut",
 ];
 
-pub(crate) fn generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
+pub(crate) fn for_generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
     let c = ty
         .type_bound_list()
         .and_then(|bounds| bounds.syntax().text().char_at(0.into()))
@@ -83,7 +83,8 @@ pub(crate) fn generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
 /// It also applies heuristics to filter out less informative names
 ///
 /// Currently it sticks to the first name found.
-pub(crate) fn variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String {
+// FIXME: Microoptimize and return a `SmolStr` here.
+pub(crate) fn for_variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String {
     // `from_param` does not benifit from stripping
     // it need the largest context possible
     // so we check firstmost
@@ -284,7 +285,7 @@ fn check(ra_fixture: &str, expected: &str) {
             frange.range,
             "selection is not an expression(yet contained in one)"
         );
-        let name = variable(&expr, &sema);
+        let name = for_variable(&expr, &sema);
         assert_eq!(&name, expected);
     }