Uniformalize naming
This commit is contained in:
parent
4d49b5d174
commit
d8caf56dfc
6 changed files with 17 additions and 22 deletions
|
@ -36,7 +36,7 @@ pub(crate) fn add_new(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
|||
|
||||
// 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,
|
||||
};
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ fn build_pat(var: ast::EnumVariant) -> Option<ast::Pat> {
|
|||
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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -30,13 +30,9 @@ pub struct EnumVariantData {
|
|||
pub variant_data: Arc<VariantData>,
|
||||
}
|
||||
|
||||
/// 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<LocalStructFieldId, StructFieldData>),
|
||||
pub enum VariantData {
|
||||
Record(Arena<LocalStructFieldId, StructFieldData>),
|
||||
Tuple(Arena<LocalStructFieldId, StructFieldData>),
|
||||
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<LocalStructFieldId, StructFieldData>> {
|
||||
match &self.0 {
|
||||
VariantDataInner::Struct(fields) | VariantDataInner::Tuple(fields) => Some(fields),
|
||||
match self {
|
||||
VariantData::Record(fields) | VariantData::Tuple(fields) => Some(fields),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ impl FunctionSignature {
|
|||
pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> {
|
||||
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<Self> {
|
||||
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,
|
||||
_ => (),
|
||||
};
|
||||
|
||||
|
|
|
@ -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<N: AstNode>(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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue