Skip to content

Commit 984d20a

Browse files
committed
cleanups
1 parent d9c9f6d commit 984d20a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

crates/ide_assists/src/handlers/extract_variable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
5454

5555
let var_name = match &field_shorthand {
5656
Some(it) => it.to_string(),
57-
None => suggest_name::variable(&to_extract, &ctx.sema),
57+
None => suggest_name::for_variable(&to_extract, &ctx.sema),
5858
};
5959
let expr_range = match &field_shorthand {
6060
Some(it) => it.syntax().text_range().cover(to_extract.syntax().text_range()),

crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn replace_impl_trait_with_generic(
2929
"Replace impl trait with generic",
3030
target,
3131
|edit| {
32-
let type_param_name = suggest_name::generic_parameter(&impl_trait_type);
32+
let type_param_name = suggest_name::for_generic_parameter(&impl_trait_type);
3333

3434
let generic_param_list = fn_
3535
.generic_param_list()

crates/ide_assists/src/utils/suggest_name.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const USELESS_METHODS: &[&str] = &[
5757
"iter_mut",
5858
];
5959

60-
pub(crate) fn generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
60+
pub(crate) fn for_generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
6161
let c = ty
6262
.type_bound_list()
6363
.and_then(|bounds| bounds.syntax().text().char_at(0.into()))
@@ -83,7 +83,8 @@ pub(crate) fn generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
8383
/// It also applies heuristics to filter out less informative names
8484
///
8585
/// Currently it sticks to the first name found.
86-
pub(crate) fn variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String {
86+
// FIXME: Microoptimize and return a `SmolStr` here.
87+
pub(crate) fn for_variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String {
8788
// `from_param` does not benifit from stripping
8889
// it need the largest context possible
8990
// so we check firstmost
@@ -284,7 +285,7 @@ mod tests {
284285
frange.range,
285286
"selection is not an expression(yet contained in one)"
286287
);
287-
let name = variable(&expr, &sema);
288+
let name = for_variable(&expr, &sema);
288289
assert_eq!(&name, expected);
289290
}
290291

0 commit comments

Comments
 (0)