diff --git a/Cargo.lock b/Cargo.lock index c604298ec1..007f05b4d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,7 +921,6 @@ dependencies = [ "ra_db", "ra_fmt", "ra_hir", - "ra_hir_expand", "ra_ide_db", "ra_prof", "ra_syntax", diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index f3481bdeb1..3bcf58ba4b 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -20,6 +20,5 @@ ra_fmt = { path = "../ra_fmt" } ra_prof = { path = "../ra_prof" } ra_db = { path = "../ra_db" } ra_ide_db = { path = "../ra_ide_db" } -hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } hir = { path = "../ra_hir", package = "ra_hir" } 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 3250eed5bd..3592838029 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 @@ -use hir_expand::name::AsName; use ra_ide_db::{ defs::Definition, imports_locator::ImportsLocator, search::Reference, RootDatabase, }; @@ -15,14 +14,14 @@ use crate::{ AssistContext, AssistId, Assists, }; use ast::{ArgListOwner, VisibilityOwner}; -use hir::{EnumVariant, Module, ModuleDef}; +use hir::{AsName, EnumVariant, Module, ModuleDef}; use ra_db::FileId; use ra_fmt::leading_indent; use rustc_hash::FxHashSet; // Assist extract_struct_from_enum // -// Extracts a from struct from enum variant +// Extracts a struct from enum variant // // ``` // enum A { <|>One(u32, u32) } @@ -41,7 +40,7 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) - }; let variant_name = variant.name()?.to_string(); let enum_ast = variant.parent_enum(); - let enum_name = enum_ast.name().unwrap().to_string(); + let enum_name = enum_ast.name()?.to_string(); let visibility = enum_ast.visibility(); let variant_hir = ctx.sema.to_def(&variant)?; @@ -88,13 +87,12 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) - } fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool { - let module_defs = variant.parent_enum(db).module(db).scope(db, None); - for (name, _) in module_defs { - if name.to_string() == variant_name.to_string() { - return true; - } - } - false + variant + .parent_enum(db) + .module(db) + .scope(db, None) + .into_iter() + .any(|(name, _)| name.to_string() == variant_name.to_string()) } 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 c5df4ac24d..4af0f046a7 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -70,7 +70,8 @@ pub use hir_def::{ type_ref::Mutability, }; pub use hir_expand::{ - hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, - MacroFile, Origin, + hygiene::Hygiene, + name::{AsName, Name}, + HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin, }; pub use hir_ty::{display::HirDisplay, CallableDef};