mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
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
|
// We want to only apply this to non-union structs with named fields
|
||||||
let field_list = match (strukt.kind(), strukt.is_union()) {
|
let field_list = match (strukt.kind(), strukt.is_union()) {
|
||||||
(StructKind::Named(named), false) => named,
|
(StructKind::Record(named), false) => named,
|
||||||
_ => return None,
|
_ => 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());
|
iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count());
|
||||||
make::tuple_struct_pat(path, pats).into()
|
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());
|
let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into());
|
||||||
make::record_pat(path, pats).into()
|
make::record_pat(path, pats).into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl HasSource for StructField {
|
||||||
|
|
||||||
let field_sources = match struct_kind {
|
let field_sources = match struct_kind {
|
||||||
ast::StructKind::Tuple(fl) => fl.fields().map(|it| FieldSource::Pos(it)).collect(),
|
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(),
|
ast::StructKind::Unit => Vec::new(),
|
||||||
};
|
};
|
||||||
let value = field_sources
|
let value = field_sources
|
||||||
|
|
|
@ -30,13 +30,9 @@ pub struct EnumVariantData {
|
||||||
pub variant_data: Arc<VariantData>,
|
pub variant_data: Arc<VariantData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fields of an enum variant or struct
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct VariantData(VariantDataInner);
|
pub enum VariantData {
|
||||||
|
Record(Arena<LocalStructFieldId, StructFieldData>),
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
enum VariantDataInner {
|
|
||||||
Struct(Arena<LocalStructFieldId, StructFieldData>),
|
|
||||||
Tuple(Arena<LocalStructFieldId, StructFieldData>),
|
Tuple(Arena<LocalStructFieldId, StructFieldData>),
|
||||||
Unit,
|
Unit,
|
||||||
}
|
}
|
||||||
|
@ -86,7 +82,7 @@ impl EnumData {
|
||||||
|
|
||||||
impl VariantData {
|
impl VariantData {
|
||||||
fn new(flavor: ast::StructKind) -> Self {
|
fn new(flavor: ast::StructKind) -> Self {
|
||||||
let inner = match flavor {
|
match flavor {
|
||||||
ast::StructKind::Tuple(fl) => {
|
ast::StructKind::Tuple(fl) => {
|
||||||
let fields = fl
|
let fields = fl
|
||||||
.fields()
|
.fields()
|
||||||
|
@ -96,9 +92,9 @@ impl VariantData {
|
||||||
type_ref: TypeRef::from_ast_opt(fd.type_ref()),
|
type_ref: TypeRef::from_ast_opt(fd.type_ref()),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
VariantDataInner::Tuple(fields)
|
VariantData::Tuple(fields)
|
||||||
}
|
}
|
||||||
ast::StructKind::Named(fl) => {
|
ast::StructKind::Record(fl) => {
|
||||||
let fields = fl
|
let fields = fl
|
||||||
.fields()
|
.fields()
|
||||||
.map(|fd| StructFieldData {
|
.map(|fd| StructFieldData {
|
||||||
|
@ -106,16 +102,15 @@ impl VariantData {
|
||||||
type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
|
type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
VariantDataInner::Struct(fields)
|
VariantData::Record(fields)
|
||||||
}
|
}
|
||||||
ast::StructKind::Unit => VariantDataInner::Unit,
|
ast::StructKind::Unit => VariantData::Unit,
|
||||||
};
|
}
|
||||||
VariantData(inner)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fields(&self) -> Option<&Arena<LocalStructFieldId, StructFieldData>> {
|
pub fn fields(&self) -> Option<&Arena<LocalStructFieldId, StructFieldData>> {
|
||||||
match &self.0 {
|
match self {
|
||||||
VariantDataInner::Struct(fields) | VariantDataInner::Tuple(fields) => Some(fields),
|
VariantData::Record(fields) | VariantData::Tuple(fields) => Some(fields),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl FunctionSignature {
|
||||||
pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> {
|
pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> {
|
||||||
let node: ast::StructDef = st.source(db).value;
|
let node: ast::StructDef = st.source(db).value;
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
ast::StructKind::Named(_) => return None,
|
ast::StructKind::Record(_) => return None,
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ impl FunctionSignature {
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
let node: ast::EnumVariant = variant.source(db).value;
|
let node: ast::EnumVariant = variant.source(db).value;
|
||||||
match node.kind() {
|
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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum StructKind {
|
pub enum StructKind {
|
||||||
|
Record(ast::RecordFieldDefList),
|
||||||
Tuple(ast::TupleFieldDefList),
|
Tuple(ast::TupleFieldDefList),
|
||||||
Named(ast::RecordFieldDefList),
|
|
||||||
Unit,
|
Unit,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StructKind {
|
impl StructKind {
|
||||||
fn from_node<N: AstNode>(node: &N) -> StructKind {
|
fn from_node<N: AstNode>(node: &N) -> StructKind {
|
||||||
if let Some(nfdl) = child_opt::<_, ast::RecordFieldDefList>(node) {
|
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) {
|
} else if let Some(pfl) = child_opt::<_, ast::TupleFieldDefList>(node) {
|
||||||
StructKind::Tuple(pfl)
|
StructKind::Tuple(pfl)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue