Skip to content

Commit ccdcd52

Browse files
committed
Add extra test to extract_struct_from_enum_variant
1 parent 9454a9e commit ccdcd52

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

crates/assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn insert_import(
140140
enum_module_def.clone(),
141141
ctx.config.insert_use.prefix_kind,
142142
);
143-
if let Some(mut mod_path) = mod_path.filter(|path| !path.is_ident()) {
143+
if let Some(mut mod_path) = mod_path {
144144
mod_path.segments.pop();
145145
mod_path.segments.push(variant_hir_name.clone());
146146
let scope = ImportScope::find_insert_use_container(scope_node, ctx)?;
@@ -449,6 +449,33 @@ fn f() {
449449
)
450450
}
451451

452+
#[test]
453+
fn test_extract_struct_record_nested_call_exp() {
454+
check_assist(
455+
extract_struct_from_enum_variant,
456+
r#"
457+
enum A { <|>One { a: u32, b: u32 } }
458+
459+
struct B(A);
460+
461+
fn foo() {
462+
let _ = B(A::One { a: 1, b: 2 });
463+
}
464+
"#,
465+
r#"
466+
struct One{ pub a: u32, pub b: u32 }
467+
468+
enum A { One(One) }
469+
470+
struct B(A);
471+
472+
fn foo() {
473+
let _ = B(A::One(One { a: 1, b: 2 }));
474+
}
475+
"#,
476+
);
477+
}
478+
452479
fn check_not_applicable(ra_fixture: &str) {
453480
let fixture =
454481
format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);

0 commit comments

Comments
 (0)