aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-22 18:52:44 +0000
committerGitHub <[email protected]>2019-11-22 18:52:44 +0000
commit5b19202e00fffe62a1a9c07f4b974f0affdd0c66 (patch)
tree0accd61a43762a6a34ae046ef6e23c3f7a930910
parent4d49b5d174430feede9833c5e66c39ee41b5fa3e (diff)
parentd8caf56dfc9eb3cdddff05b58b954a78cf1b9476 (diff)
Merge #2361
2361: Uniformalize naming r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_assists/src/assists/add_new.rs2
-rw-r--r--crates/ra_assists/src/assists/fill_match_arms.rs2
-rw-r--r--crates/ra_hir/src/code_model/src.rs2
-rw-r--r--crates/ra_hir_def/src/adt.rs25
-rw-r--r--crates/ra_ide_api/src/display/function_signature.rs4
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs4
6 files changed, 17 insertions, 22 deletions
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<impl HirDatabase>) -> Option<Assist> {
36 36
37 // We want to only apply this to non-union structs with named fields 37 // We want to only apply this to non-union structs with named fields
38 let field_list = match (strukt.kind(), strukt.is_union()) { 38 let field_list = match (strukt.kind(), strukt.is_union()) {
39 (StructKind::Named(named), false) => named, 39 (StructKind::Record(named), false) => named,
40 _ => return None, 40 _ => return None,
41 }; 41 };
42 42
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<ast::Pat> {
101 iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count()); 101 iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count());
102 make::tuple_struct_pat(path, pats).into() 102 make::tuple_struct_pat(path, pats).into()
103 } 103 }
104 ast::StructKind::Named(field_list) => { 104 ast::StructKind::Record(field_list) => {
105 let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into()); 105 let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into());
106 make::record_pat(path, pats).into() 106 make::record_pat(path, pats).into()
107 } 107 }
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 {
63 63
64 let field_sources = match struct_kind { 64 let field_sources = match struct_kind {
65 ast::StructKind::Tuple(fl) => fl.fields().map(|it| FieldSource::Pos(it)).collect(), 65 ast::StructKind::Tuple(fl) => fl.fields().map(|it| FieldSource::Pos(it)).collect(),
66 ast::StructKind::Named(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(), 66 ast::StructKind::Record(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(),
67 ast::StructKind::Unit => Vec::new(), 67 ast::StructKind::Unit => Vec::new(),
68 }; 68 };
69 let value = field_sources 69 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 {
30 pub variant_data: Arc<VariantData>, 30 pub variant_data: Arc<VariantData>,
31} 31}
32 32
33/// Fields of an enum variant or struct
34#[derive(Debug, Clone, PartialEq, Eq)] 33#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct VariantData(VariantDataInner); 34pub enum VariantData {
36 35 Record(Arena<LocalStructFieldId, StructFieldData>),
37#[derive(Debug, Clone, PartialEq, Eq)]
38enum VariantDataInner {
39 Struct(Arena<LocalStructFieldId, StructFieldData>),
40 Tuple(Arena<LocalStructFieldId, StructFieldData>), 36 Tuple(Arena<LocalStructFieldId, StructFieldData>),
41 Unit, 37 Unit,
42} 38}
@@ -86,7 +82,7 @@ impl EnumData {
86 82
87impl VariantData { 83impl VariantData {
88 fn new(flavor: ast::StructKind) -> Self { 84 fn new(flavor: ast::StructKind) -> Self {
89 let inner = match flavor { 85 match flavor {
90 ast::StructKind::Tuple(fl) => { 86 ast::StructKind::Tuple(fl) => {
91 let fields = fl 87 let fields = fl
92 .fields() 88 .fields()
@@ -96,9 +92,9 @@ impl VariantData {
96 type_ref: TypeRef::from_ast_opt(fd.type_ref()), 92 type_ref: TypeRef::from_ast_opt(fd.type_ref()),
97 }) 93 })
98 .collect(); 94 .collect();
99 VariantDataInner::Tuple(fields) 95 VariantData::Tuple(fields)
100 } 96 }
101 ast::StructKind::Named(fl) => { 97 ast::StructKind::Record(fl) => {
102 let fields = fl 98 let fields = fl
103 .fields() 99 .fields()
104 .map(|fd| StructFieldData { 100 .map(|fd| StructFieldData {
@@ -106,16 +102,15 @@ impl VariantData {
106 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), 102 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
107 }) 103 })
108 .collect(); 104 .collect();
109 VariantDataInner::Struct(fields) 105 VariantData::Record(fields)
110 } 106 }
111 ast::StructKind::Unit => VariantDataInner::Unit, 107 ast::StructKind::Unit => VariantData::Unit,
112 }; 108 }
113 VariantData(inner)
114 } 109 }
115 110
116 pub fn fields(&self) -> Option<&Arena<LocalStructFieldId, StructFieldData>> { 111 pub fn fields(&self) -> Option<&Arena<LocalStructFieldId, StructFieldData>> {
117 match &self.0 { 112 match self {
118 VariantDataInner::Struct(fields) | VariantDataInner::Tuple(fields) => Some(fields), 113 VariantData::Record(fields) | VariantData::Tuple(fields) => Some(fields),
119 _ => None, 114 _ => None,
120 } 115 }
121 } 116 }
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 {
55 pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> { 55 pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> {
56 let node: ast::StructDef = st.source(db).value; 56 let node: ast::StructDef = st.source(db).value;
57 match node.kind() { 57 match node.kind() {
58 ast::StructKind::Named(_) => return None, 58 ast::StructKind::Record(_) => return None,
59 _ => (), 59 _ => (),
60 }; 60 };
61 61
@@ -89,7 +89,7 @@ impl FunctionSignature {
89 ) -> Option<Self> { 89 ) -> Option<Self> {
90 let node: ast::EnumVariant = variant.source(db).value; 90 let node: ast::EnumVariant = variant.source(db).value;
91 match node.kind() { 91 match node.kind() {
92 ast::StructKind::Named(_) | ast::StructKind::Unit => return None, 92 ast::StructKind::Record(_) | ast::StructKind::Unit => return None,
93 _ => (), 93 _ => (),
94 }; 94 };
95 95
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 {
178 178
179#[derive(Debug, Clone, PartialEq, Eq)] 179#[derive(Debug, Clone, PartialEq, Eq)]
180pub enum StructKind { 180pub enum StructKind {
181 Record(ast::RecordFieldDefList),
181 Tuple(ast::TupleFieldDefList), 182 Tuple(ast::TupleFieldDefList),
182 Named(ast::RecordFieldDefList),
183 Unit, 183 Unit,
184} 184}
185 185
186impl StructKind { 186impl StructKind {
187 fn from_node<N: AstNode>(node: &N) -> StructKind { 187 fn from_node<N: AstNode>(node: &N) -> StructKind {
188 if let Some(nfdl) = child_opt::<_, ast::RecordFieldDefList>(node) { 188 if let Some(nfdl) = child_opt::<_, ast::RecordFieldDefList>(node) {
189 StructKind::Named(nfdl) 189 StructKind::Record(nfdl)
190 } else if let Some(pfl) = child_opt::<_, ast::TupleFieldDefList>(node) { 190 } else if let Some(pfl) = child_opt::<_, ast::TupleFieldDefList>(node) {
191 StructKind::Tuple(pfl) 191 StructKind::Tuple(pfl)
192 } else { 192 } else {