File tree 1 file changed +26
-0
lines changed
crates/ide-assists/src/handlers
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,32 @@ fn create_struct_def(
246
246
Either :: Left ( field_list) => {
247
247
let field_list = field_list. clone_for_update ( ) ;
248
248
249
+ // replace `Self` with the enum name when construct struct def
250
+ field_list
251
+ . fields ( )
252
+ . filter_map ( |field| match field. ty ( ) ? {
253
+ ast:: Type :: PathType ( p) => {
254
+ let generic_arg_list = p. path ( ) ?. segment ( ) ?. generic_arg_list ( ) ?;
255
+ Some (
256
+ generic_arg_list
257
+ . generic_args ( )
258
+ . filter_map ( |generic_arg| {
259
+ if generic_arg. to_string ( ) == "Self" {
260
+ let type_arg =
261
+ make:: type_arg ( make:: ty ( & enum_. name ( ) ?. to_string ( ) ) )
262
+ . clone_for_update ( ) ;
263
+ Some ( ted:: replace ( generic_arg. syntax ( ) , type_arg. syntax ( ) ) )
264
+ } else {
265
+ None
266
+ }
267
+ } )
268
+ . count ( ) ,
269
+ )
270
+ }
271
+ _ => None ,
272
+ } )
273
+ . count ( ) ;
274
+
249
275
if let Some ( vis) = & enum_vis {
250
276
field_list
251
277
. fields ( )
You can’t perform that action at this time.
0 commit comments