diff options
author | Mikhail Rakhmanov <[email protected]> | 2020-05-23 00:41:08 +0100 |
---|---|---|
committer | Mikhail Rakhmanov <[email protected]> | 2020-05-23 00:41:08 +0100 |
commit | 6ee1c60c9cff781e10d6379f68fc951378403f6b (patch) | |
tree | 941d45aed0effe537c4a0742523f074b53e1a6db /crates/ra_assists/src | |
parent | 4984520ef565e926ba08c6512715ed631e4527e4 (diff) |
Further review fixes
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r-- | crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | 20 |
1 files changed, 9 insertions, 11 deletions
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 { |