Use GenericArgList for make::impl{_trait}

`make::impl_` no longer merges generic params and args in order to be in line
with `make::impl_`, which doesn't do it either.
This commit is contained in:
DropDemBits 2023-12-10 21:20:09 -05:00
parent 13707845f7
commit 8c0661b2de
No known key found for this signature in database
GPG key ID: 7FE02A6C1EDFA075
2 changed files with 11 additions and 19 deletions

View file

@ -161,13 +161,13 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
Some(impl_def) => edit.make_mut(impl_def), Some(impl_def) => edit.make_mut(impl_def),
None => { None => {
let name = &strukt_name.to_string(); let name = &strukt_name.to_string();
let params = strukt.generic_param_list(); let ty_params = strukt.generic_param_list();
let ty_params = params; let ty_args = ty_params.as_ref().map(|it| it.to_generic_args());
let where_clause = strukt.where_clause(); let where_clause = strukt.where_clause();
let impl_def = make::impl_( let impl_def = make::impl_(
ty_params, ty_params,
None, ty_args,
make::ty_path(make::ext::ident_path(name)), make::ty_path(make::ext::ident_path(name)),
where_clause, where_clause,
None, None,

View file

@ -236,20 +236,14 @@ fn merge_where_clause(
pub fn impl_( pub fn impl_(
generic_params: Option<ast::GenericParamList>, generic_params: Option<ast::GenericParamList>,
generic_args: Option<ast::GenericParamList>, generic_args: Option<ast::GenericArgList>,
path_type: ast::Type, path_type: ast::Type,
where_clause: Option<ast::WhereClause>, where_clause: Option<ast::WhereClause>,
body: Option<Vec<either::Either<ast::Attr, ast::AssocItem>>>, body: Option<Vec<either::Either<ast::Attr, ast::AssocItem>>>,
) -> ast::Impl { ) -> ast::Impl {
let (gen_params, tr_gen_args) = match (generic_params, generic_args) { let gen_args = generic_args.map_or_else(String::new, |it| it.to_string());
(None, None) => (String::new(), String::new()),
(None, Some(args)) => (String::new(), args.to_generic_args().to_string()), let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
(Some(params), None) => (params.to_string(), params.to_generic_args().to_string()),
(Some(params), Some(args)) => match merge_gen_params(Some(params.clone()), Some(args)) {
Some(merged) => (params.to_string(), merged.to_generic_args().to_string()),
None => (params.to_string(), String::new()),
},
};
let where_clause = match where_clause { let where_clause = match where_clause {
Some(pr) => pr.to_string(), Some(pr) => pr.to_string(),
@ -261,7 +255,7 @@ pub fn impl_(
None => String::new(), None => String::new(),
}; };
ast_from_text(&format!("impl{gen_params} {path_type}{tr_gen_args}{where_clause}{{{}}}", body)) ast_from_text(&format!("impl{gen_params} {path_type}{gen_args}{where_clause}{{{body}}}"))
} }
pub fn impl_trait( pub fn impl_trait(
@ -282,10 +276,8 @@ pub fn impl_trait(
let trait_gen_args = trait_gen_args.map(|args| args.to_string()).unwrap_or_default(); let trait_gen_args = trait_gen_args.map(|args| args.to_string()).unwrap_or_default();
let type_gen_args = type_gen_args.map(|args| args.to_string()).unwrap_or_default(); let type_gen_args = type_gen_args.map(|args| args.to_string()).unwrap_or_default();
let gen_params = match merge_gen_params(trait_gen_params, type_gen_params) { let gen_params = merge_gen_params(trait_gen_params, type_gen_params)
Some(pars) => pars.to_string(), .map_or_else(String::new, |it| it.to_string());
None => String::new(),
};
let is_negative = if is_negative { "! " } else { "" }; let is_negative = if is_negative { "! " } else { "" };
@ -297,7 +289,7 @@ pub fn impl_trait(
None => String::new(), None => String::new(),
}; };
ast_from_text(&format!("{is_unsafe}impl{gen_params} {is_negative}{path_type}{trait_gen_args} for {ty}{type_gen_args}{where_clause}{{{}}}" , body)) ast_from_text(&format!("{is_unsafe}impl{gen_params} {is_negative}{path_type}{trait_gen_args} for {ty}{type_gen_args}{where_clause}{{{body}}}"))
} }
pub fn impl_trait_type(bounds: ast::TypeBoundList) -> ast::ImplTraitType { pub fn impl_trait_type(bounds: ast::TypeBoundList) -> ast::ImplTraitType {