mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 19:23:50 +00:00
cleanups
This commit is contained in:
parent
d9c9f6dc2c
commit
984d20aad8
@ -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()),
|
||||
|
@ -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()
|
||||
|
@ -57,7 +57,7 @@ const USELESS_METHODS: &[&str] = &[
|
||||
"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 @@ mod tests {
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user