refactor: apply suggestions

See PR #11194
This commit is contained in:
Côme ALLART 2022-01-07 14:04:03 +01:00
parent c2d3f90886
commit 1b5c60f549

View file

@ -229,15 +229,17 @@ fn self_type(ast_func: &ast::Fn) -> Option<ast::Type> {
/// Output the real name of `Self` like `MyType<T>`, without the lifetimes. /// Output the real name of `Self` like `MyType<T>`, without the lifetimes.
fn self_type_without_lifetimes(ast_func: &ast::Fn) -> Option<String> { fn self_type_without_lifetimes(ast_func: &ast::Fn) -> Option<String> {
let path_segment = let path_segment = match self_type(ast_func)? {
ast::PathType::cast(self_type(ast_func)?.syntax().clone())?.path()?.segment()?; ast::Type::PathType(path_type) => path_type.path()?.segment()?,
_ => return None,
};
let mut name = path_segment.name_ref()?.to_string(); let mut name = path_segment.name_ref()?.to_string();
let generics = path_segment let generics = path_segment
.generic_arg_list()? .generic_arg_list()?
.generic_args() .generic_args()
.filter(|generic| matches!(generic, ast::GenericArg::TypeArg(_))) .filter(|generic| matches!(generic, ast::GenericArg::TypeArg(_)))
.map(|generic| generic.to_string()); .map(|generic| generic.to_string());
let generics: String = Itertools::intersperse(generics, ", ".to_string()).collect(); let generics: String = generics.format(", ").to_string();
if !generics.is_empty() { if !generics.is_empty() {
name.push('<'); name.push('<');
name.push_str(&generics); name.push_str(&generics);
@ -325,7 +327,7 @@ fn arguments_from_params(param_list: &ast::ParamList) -> String {
}, },
_ => "_".to_string(), _ => "_".to_string(),
}); });
Itertools::intersperse(args_iter, ", ".to_string()).collect() args_iter.format(", ").to_string()
} }
/// Helper function to build a function call. `None` if expected `self_name` was not provided /// Helper function to build a function call. `None` if expected `self_name` was not provided