mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Further review fixes
This commit is contained in:
parent
4984520ef5
commit
6ee1c60c9c
4 changed files with 12 additions and 15 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -921,7 +921,6 @@ dependencies = [
|
|||
"ra_db",
|
||||
"ra_fmt",
|
||||
"ra_hir",
|
||||
"ra_hir_expand",
|
||||
"ra_ide_db",
|
||||
"ra_prof",
|
||||
"ra_syntax",
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in a new issue