From a38a79e2ba12c80459b81d21be8a59aeb9434f5d Mon Sep 17 00:00:00 2001 From: Young-Flash <871946895@qq.com> Date: Wed, 27 Dec 2023 19:49:50 +0800 Subject: [PATCH] use SyntaxKind instead of "Self" literal comparison --- .../extract_struct_from_enum_variant.rs | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) 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 2e0a628eee7..3aa3069a23d 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 @@ -250,24 +250,21 @@ fn create_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(), - ) - } + ast::Type::PathType(p) => Some( + p.syntax() + .descendants_with_tokens() + .filter_map(|it| { + if it.kind() == T![Self] { + let type_arg = + make::type_arg(make::ty(&enum_.name()?.to_string())) + .clone_for_update(); + Some(ted::replace(it, type_arg.syntax())) + } else { + None + } + }) + .count(), + ), _ => None, }) .count();