diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/ra_assists/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 5 |
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" } | |||
20 | ra_prof = { path = "../ra_prof" } | 20 | ra_prof = { path = "../ra_prof" } |
21 | ra_db = { path = "../ra_db" } | 21 | ra_db = { path = "../ra_db" } |
22 | ra_ide_db = { path = "../ra_ide_db" } | 22 | ra_ide_db = { path = "../ra_ide_db" } |
23 | hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } | ||
24 | hir = { path = "../ra_hir", package = "ra_hir" } | 23 | hir = { path = "../ra_hir", package = "ra_hir" } |
25 | test_utils = { path = "../test_utils" } | 24 | test_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 @@ | |||
1 | use hir_expand::name::AsName; | ||
2 | use ra_ide_db::{ | 1 | use 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 | }; |
17 | use ast::{ArgListOwner, VisibilityOwner}; | 16 | use ast::{ArgListOwner, VisibilityOwner}; |
18 | use hir::{EnumVariant, Module, ModuleDef}; | 17 | use hir::{AsName, EnumVariant, Module, ModuleDef}; |
19 | use ra_db::FileId; | 18 | use ra_db::FileId; |
20 | use ra_fmt::leading_indent; | 19 | use ra_fmt::leading_indent; |
21 | use rustc_hash::FxHashSet; | 20 | use 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 | ||
90 | fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool { | 89 | fn 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 | ||
100 | fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef { | 98 | fn 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 | }; |
72 | pub use hir_expand::{ | 72 | pub 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 | }; |
76 | pub use hir_ty::{display::HirDisplay, CallableDef}; | 77 | pub use hir_ty::{display::HirDisplay, CallableDef}; |