diff --git a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs index 37db27a8fc..b55344f157 100644 --- a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs @@ -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()