fix: extract_struct_from_enum_variant should resolve Self generic arg

This commit is contained in:
Young-Flash 2023-12-26 21:23:41 +08:00
parent 85fb463fc5
commit 8a0a3b2493

View file

@ -246,6 +246,32 @@ fn create_struct_def(
Either::Left(field_list) => {
let field_list = field_list.clone_for_update();
// replace `Self` with the enum name when construct struct def
field_list
.fields()
.filter_map(|field| match field.ty()? {
ast::Type::PathType(p) => {
let generic_arg_list = p.path()?.segment()?.generic_arg_list()?;
Some(
generic_arg_list
.generic_args()
.filter_map(|generic_arg| {
if generic_arg.to_string() == "Self" {
let type_arg =
make::type_arg(make::ty(&enum_.name()?.to_string()))
.clone_for_update();
Some(ted::replace(generic_arg.syntax(), type_arg.syntax()))
} else {
None
}
})
.count(),
)
}
_ => None,
})
.count();
if let Some(vis) = &enum_vis {
field_list
.fields()