From d8caf56dfc9eb3cdddff05b58b954a78cf1b9476 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 21:52:06 +0300 Subject: Uniformalize naming --- crates/ra_assists/src/assists/add_new.rs | 2 +- crates/ra_assists/src/assists/fill_match_arms.rs | 2 +- crates/ra_hir/src/code_model/src.rs | 2 +- crates/ra_hir_def/src/adt.rs | 25 +++++++++------------- .../ra_ide_api/src/display/function_signature.rs | 4 ++-- crates/ra_syntax/src/ast/extensions.rs | 4 ++-- 6 files changed, 17 insertions(+), 22 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/assists/add_new.rs index b5f8afb4e..ee8bff346 100644 --- a/crates/ra_assists/src/assists/add_new.rs +++ b/crates/ra_assists/src/assists/add_new.rs @@ -36,7 +36,7 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option { // We want to only apply this to non-union structs with named fields let field_list = match (strukt.kind(), strukt.is_union()) { - (StructKind::Named(named), false) => named, + (StructKind::Record(named), false) => named, _ => return None, }; diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs index 9354466d9..8482897c5 100644 --- a/crates/ra_assists/src/assists/fill_match_arms.rs +++ b/crates/ra_assists/src/assists/fill_match_arms.rs @@ -101,7 +101,7 @@ fn build_pat(var: ast::EnumVariant) -> Option { iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count()); make::tuple_struct_pat(path, pats).into() } - ast::StructKind::Named(field_list) => { + ast::StructKind::Record(field_list) => { let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into()); make::record_pat(path, pats).into() } diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 4aa427de4..fc466c1f0 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -63,7 +63,7 @@ impl HasSource for StructField { let field_sources = match struct_kind { ast::StructKind::Tuple(fl) => fl.fields().map(|it| FieldSource::Pos(it)).collect(), - ast::StructKind::Named(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(), + ast::StructKind::Record(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(), ast::StructKind::Unit => Vec::new(), }; let value = field_sources diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index d04f54e15..2bd18255c 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -30,13 +30,9 @@ pub struct EnumVariantData { pub variant_data: Arc, } -/// Fields of an enum variant or struct #[derive(Debug, Clone, PartialEq, Eq)] -pub struct VariantData(VariantDataInner); - -#[derive(Debug, Clone, PartialEq, Eq)] -enum VariantDataInner { - Struct(Arena), +pub enum VariantData { + Record(Arena), Tuple(Arena), Unit, } @@ -86,7 +82,7 @@ impl EnumData { impl VariantData { fn new(flavor: ast::StructKind) -> Self { - let inner = match flavor { + match flavor { ast::StructKind::Tuple(fl) => { let fields = fl .fields() @@ -96,9 +92,9 @@ impl VariantData { type_ref: TypeRef::from_ast_opt(fd.type_ref()), }) .collect(); - VariantDataInner::Tuple(fields) + VariantData::Tuple(fields) } - ast::StructKind::Named(fl) => { + ast::StructKind::Record(fl) => { let fields = fl .fields() .map(|fd| StructFieldData { @@ -106,16 +102,15 @@ impl VariantData { type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), }) .collect(); - VariantDataInner::Struct(fields) + VariantData::Record(fields) } - ast::StructKind::Unit => VariantDataInner::Unit, - }; - VariantData(inner) + ast::StructKind::Unit => VariantData::Unit, + } } pub fn fields(&self) -> Option<&Arena> { - match &self.0 { - VariantDataInner::Struct(fields) | VariantDataInner::Tuple(fields) => Some(fields), + match self { + VariantData::Record(fields) | VariantData::Tuple(fields) => Some(fields), _ => None, } } diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs index f42dffc87..d96de4e4c 100644 --- a/crates/ra_ide_api/src/display/function_signature.rs +++ b/crates/ra_ide_api/src/display/function_signature.rs @@ -55,7 +55,7 @@ impl FunctionSignature { pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option { let node: ast::StructDef = st.source(db).value; match node.kind() { - ast::StructKind::Named(_) => return None, + ast::StructKind::Record(_) => return None, _ => (), }; @@ -89,7 +89,7 @@ impl FunctionSignature { ) -> Option { let node: ast::EnumVariant = variant.source(db).value; match node.kind() { - ast::StructKind::Named(_) | ast::StructKind::Unit => return None, + ast::StructKind::Record(_) | ast::StructKind::Unit => return None, _ => (), }; diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 4851dacb2..513ed7920 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -178,15 +178,15 @@ impl ast::ImplBlock { #[derive(Debug, Clone, PartialEq, Eq)] pub enum StructKind { + Record(ast::RecordFieldDefList), Tuple(ast::TupleFieldDefList), - Named(ast::RecordFieldDefList), Unit, } impl StructKind { fn from_node(node: &N) -> StructKind { if let Some(nfdl) = child_opt::<_, ast::RecordFieldDefList>(node) { - StructKind::Named(nfdl) + StructKind::Record(nfdl) } else if let Some(pfl) = child_opt::<_, ast::TupleFieldDefList>(node) { StructKind::Tuple(pfl) } else { -- cgit v1.2.3