]> git.lizzy.rs Git - rust.git/commitdiff
Add extra test to extract_struct_from_enum_variant
authorLukas Wirth <lukastw97@gmail.com>
Thu, 12 Nov 2020 16:47:58 +0000 (17:47 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Thu, 12 Nov 2020 17:44:37 +0000 (18:44 +0100)
crates/assists/src/handlers/extract_struct_from_enum_variant.rs

index ef4dce4770d8465515bd98938c87113204e150a2..067afabf2edf7b45c765ac40c32d82e693ad10e0 100644 (file)
@@ -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);