mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-29 05:14:18 +00:00
fix: extract_struct_from_enum_variant should resolve Self
generic arg
This commit is contained in:
parent
85fb463fc5
commit
8a0a3b2493
1 changed files with 26 additions and 0 deletions
|
@ -246,6 +246,32 @@ fn create_struct_def(
|
||||||
Either::Left(field_list) => {
|
Either::Left(field_list) => {
|
||||||
let field_list = field_list.clone_for_update();
|
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 {
|
if let Some(vis) = &enum_vis {
|
||||||
field_list
|
field_list
|
||||||
.fields()
|
.fields()
|
||||||
|
|
Loading…
Reference in a new issue