From ccdcd52975c16df217188ccb196f45041b6f0973 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 12 Nov 2020 17:47:58 +0100 Subject: Add extra test to extract_struct_from_enum_variant --- .../handlers/extract_struct_from_enum_variant.rs | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'crates/assists/src/handlers/extract_struct_from_enum_variant.rs') diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index ef4dce477..067afabf2 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs @@ -140,7 +140,7 @@ fn insert_import( enum_module_def.clone(), ctx.config.insert_use.prefix_kind, ); - if let Some(mut mod_path) = mod_path.filter(|path| !path.is_ident()) { + if let Some(mut mod_path) = mod_path { mod_path.segments.pop(); mod_path.segments.push(variant_hir_name.clone()); let scope = ImportScope::find_insert_use_container(scope_node, ctx)?; @@ -449,6 +449,33 @@ fn f() { ) } + #[test] + fn test_extract_struct_record_nested_call_exp() { + check_assist( + extract_struct_from_enum_variant, + r#" +enum A { <|>One { a: u32, b: u32 } } + +struct B(A); + +fn foo() { + let _ = B(A::One { a: 1, b: 2 }); +} +"#, + r#" +struct One{ pub a: u32, pub b: u32 } + +enum A { One(One) } + +struct B(A); + +fn foo() { + let _ = B(A::One(One { a: 1, b: 2 })); +} +"#, + ); + } + fn check_not_applicable(ra_fixture: &str) { let fixture = format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); -- cgit v1.2.3