aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_assists/Cargo.toml1
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs20
-rw-r--r--crates/ra_hir/src/lib.rs5
4 files changed, 12 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c604298ec..007f05b4d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -921,7 +921,6 @@ dependencies = [
921 "ra_db", 921 "ra_db",
922 "ra_fmt", 922 "ra_fmt",
923 "ra_hir", 923 "ra_hir",
924 "ra_hir_expand",
925 "ra_ide_db", 924 "ra_ide_db",
926 "ra_prof", 925 "ra_prof",
927 "ra_syntax", 926 "ra_syntax",
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml
index f3481bdeb..3bcf58ba4 100644
--- a/crates/ra_assists/Cargo.toml
+++ b/crates/ra_assists/Cargo.toml
@@ -20,6 +20,5 @@ ra_fmt = { path = "../ra_fmt" }
20ra_prof = { path = "../ra_prof" } 20ra_prof = { path = "../ra_prof" }
21ra_db = { path = "../ra_db" } 21ra_db = { path = "../ra_db" }
22ra_ide_db = { path = "../ra_ide_db" } 22ra_ide_db = { path = "../ra_ide_db" }
23hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
24hir = { path = "../ra_hir", package = "ra_hir" } 23hir = { path = "../ra_hir", package = "ra_hir" }
25test_utils = { path = "../test_utils" } 24test_utils = { path = "../test_utils" }
diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
index 3250eed5b..359283802 100644
--- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -1,4 +1,3 @@
1use hir_expand::name::AsName;
2use ra_ide_db::{ 1use ra_ide_db::{
3 defs::Definition, imports_locator::ImportsLocator, search::Reference, RootDatabase, 2 defs::Definition, imports_locator::ImportsLocator, search::Reference, RootDatabase,
4}; 3};
@@ -15,14 +14,14 @@ use crate::{
15 AssistContext, AssistId, Assists, 14 AssistContext, AssistId, Assists,
16}; 15};
17use ast::{ArgListOwner, VisibilityOwner}; 16use ast::{ArgListOwner, VisibilityOwner};
18use hir::{EnumVariant, Module, ModuleDef}; 17use hir::{AsName, EnumVariant, Module, ModuleDef};
19use ra_db::FileId; 18use ra_db::FileId;
20use ra_fmt::leading_indent; 19use ra_fmt::leading_indent;
21use rustc_hash::FxHashSet; 20use rustc_hash::FxHashSet;
22 21
23// Assist extract_struct_from_enum 22// Assist extract_struct_from_enum
24// 23//
25// Extracts a from struct from enum variant 24// Extracts a struct from enum variant
26// 25//
27// ``` 26// ```
28// enum A { <|>One(u32, u32) } 27// enum A { <|>One(u32, u32) }
@@ -41,7 +40,7 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
41 }; 40 };
42 let variant_name = variant.name()?.to_string(); 41 let variant_name = variant.name()?.to_string();
43 let enum_ast = variant.parent_enum(); 42 let enum_ast = variant.parent_enum();
44 let enum_name = enum_ast.name().unwrap().to_string(); 43 let enum_name = enum_ast.name()?.to_string();
45 let visibility = enum_ast.visibility(); 44 let visibility = enum_ast.visibility();
46 let variant_hir = ctx.sema.to_def(&variant)?; 45 let variant_hir = ctx.sema.to_def(&variant)?;
47 46
@@ -88,13 +87,12 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
88} 87}
89 88
90fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool { 89fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool {
91 let module_defs = variant.parent_enum(db).module(db).scope(db, None); 90 variant
92 for (name, _) in module_defs { 91 .parent_enum(db)
93 if name.to_string() == variant_name.to_string() { 92 .module(db)
94 return true; 93 .scope(db, None)
95 } 94 .into_iter()
96 } 95 .any(|(name, _)| name.to_string() == variant_name.to_string())
97 false
98} 96}
99 97
100fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef { 98fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index c5df4ac24..4af0f046a 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -70,7 +70,8 @@ pub use hir_def::{
70 type_ref::Mutability, 70 type_ref::Mutability,
71}; 71};
72pub use hir_expand::{ 72pub use hir_expand::{
73 hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, 73 hygiene::Hygiene,
74 MacroFile, Origin, 74 name::{AsName, Name},
75 HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
75}; 76};
76pub use hir_ty::{display::HirDisplay, CallableDef}; 77pub use hir_ty::{display::HirDisplay, CallableDef};