aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-30 15:24:20 +0100
committerGitHub <[email protected]>2020-07-30 15:24:20 +0100
commit282702c2877e3f9002308b1b63fc472b5e799c56 (patch)
treee8ddcc0575b012ab6e8fd099746f571cc4bf304c /crates/ra_syntax/src/ast
parent323fd64abde2aced9427e4470b626a898b80a783 (diff)
parent6f8aa75329d0a4e588e58b8f22f7932bf3d3a706 (diff)
Merge #5595
5595: Rename RecordLit -> RecordExpr r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs10
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs6
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs50
-rw-r--r--crates/ra_syntax/src/ast/make.rs4
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs8
5 files changed, 40 insertions, 38 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 0110300af..8d3e42f25 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -116,18 +116,18 @@ impl ast::AssocItemList {
116 } 116 }
117} 117}
118 118
119impl ast::RecordFieldList { 119impl ast::RecordExprFieldList {
120 #[must_use] 120 #[must_use]
121 pub fn append_field(&self, field: &ast::RecordField) -> ast::RecordFieldList { 121 pub fn append_field(&self, field: &ast::RecordExprField) -> ast::RecordExprFieldList {
122 self.insert_field(InsertPosition::Last, field) 122 self.insert_field(InsertPosition::Last, field)
123 } 123 }
124 124
125 #[must_use] 125 #[must_use]
126 pub fn insert_field( 126 pub fn insert_field(
127 &self, 127 &self,
128 position: InsertPosition<&'_ ast::RecordField>, 128 position: InsertPosition<&'_ ast::RecordExprField>,
129 field: &ast::RecordField, 129 field: &ast::RecordExprField,
130 ) -> ast::RecordFieldList { 130 ) -> ast::RecordExprFieldList {
131 let is_multiline = self.syntax().text().contains_char('\n'); 131 let is_multiline = self.syntax().text().contains_char('\n');
132 let ws; 132 let ws;
133 let space = if is_multiline { 133 let space = if is_multiline {
diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs
index 8692b9bb5..365f94287 100644
--- a/crates/ra_syntax/src/ast/expr_ext.rs
+++ b/crates/ra_syntax/src/ast/expr_ext.rs
@@ -412,8 +412,8 @@ fn test_literal_with_attr() {
412 assert_eq!(lit.token().text(), r#""Hello""#); 412 assert_eq!(lit.token().text(), r#""Hello""#);
413} 413}
414 414
415impl ast::RecordField { 415impl ast::RecordExprField {
416 pub fn parent_record_lit(&self) -> ast::RecordLit { 416 pub fn parent_record_lit(&self) -> ast::RecordExpr {
417 self.syntax().ancestors().find_map(ast::RecordLit::cast).unwrap() 417 self.syntax().ancestors().find_map(ast::RecordExpr::cast).unwrap()
418 } 418 }
419} 419}
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index efe0cbe3a..9f9c06e50 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -909,30 +909,32 @@ impl MatchGuard {
909 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 909 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
910} 910}
911#[derive(Debug, Clone, PartialEq, Eq, Hash)] 911#[derive(Debug, Clone, PartialEq, Eq, Hash)]
912pub struct RecordLit { 912pub struct RecordExpr {
913 pub(crate) syntax: SyntaxNode, 913 pub(crate) syntax: SyntaxNode,
914} 914}
915impl RecordLit { 915impl RecordExpr {
916 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 916 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
917 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } 917 pub fn record_expr_field_list(&self) -> Option<RecordExprFieldList> {
918 support::child(&self.syntax)
919 }
918} 920}
919#[derive(Debug, Clone, PartialEq, Eq, Hash)] 921#[derive(Debug, Clone, PartialEq, Eq, Hash)]
920pub struct RecordFieldList { 922pub struct RecordExprFieldList {
921 pub(crate) syntax: SyntaxNode, 923 pub(crate) syntax: SyntaxNode,
922} 924}
923impl RecordFieldList { 925impl RecordExprFieldList {
924 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 926 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
925 pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) } 927 pub fn fields(&self) -> AstChildren<RecordExprField> { support::children(&self.syntax) }
926 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 928 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
927 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } 929 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) }
928 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 930 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
929} 931}
930#[derive(Debug, Clone, PartialEq, Eq, Hash)] 932#[derive(Debug, Clone, PartialEq, Eq, Hash)]
931pub struct RecordField { 933pub struct RecordExprField {
932 pub(crate) syntax: SyntaxNode, 934 pub(crate) syntax: SyntaxNode,
933} 935}
934impl ast::AttrsOwner for RecordField {} 936impl ast::AttrsOwner for RecordExprField {}
935impl RecordField { 937impl RecordExprField {
936 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 938 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
937 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 939 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
938 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 940 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
@@ -1345,7 +1347,7 @@ pub enum Expr {
1345 BlockExpr(BlockExpr), 1347 BlockExpr(BlockExpr),
1346 ReturnExpr(ReturnExpr), 1348 ReturnExpr(ReturnExpr),
1347 MatchExpr(MatchExpr), 1349 MatchExpr(MatchExpr),
1348 RecordLit(RecordLit), 1350 RecordExpr(RecordExpr),
1349 CallExpr(CallExpr), 1351 CallExpr(CallExpr),
1350 IndexExpr(IndexExpr), 1352 IndexExpr(IndexExpr),
1351 MethodCallExpr(MethodCallExpr), 1353 MethodCallExpr(MethodCallExpr),
@@ -2357,8 +2359,8 @@ impl AstNode for MatchGuard {
2357 } 2359 }
2358 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2360 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2359} 2361}
2360impl AstNode for RecordLit { 2362impl AstNode for RecordExpr {
2361 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_LIT } 2363 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR }
2362 fn cast(syntax: SyntaxNode) -> Option<Self> { 2364 fn cast(syntax: SyntaxNode) -> Option<Self> {
2363 if Self::can_cast(syntax.kind()) { 2365 if Self::can_cast(syntax.kind()) {
2364 Some(Self { syntax }) 2366 Some(Self { syntax })
@@ -2368,8 +2370,8 @@ impl AstNode for RecordLit {
2368 } 2370 }
2369 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2371 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2370} 2372}
2371impl AstNode for RecordFieldList { 2373impl AstNode for RecordExprFieldList {
2372 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_LIST } 2374 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST }
2373 fn cast(syntax: SyntaxNode) -> Option<Self> { 2375 fn cast(syntax: SyntaxNode) -> Option<Self> {
2374 if Self::can_cast(syntax.kind()) { 2376 if Self::can_cast(syntax.kind()) {
2375 Some(Self { syntax }) 2377 Some(Self { syntax })
@@ -2379,8 +2381,8 @@ impl AstNode for RecordFieldList {
2379 } 2381 }
2380 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2382 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2381} 2383}
2382impl AstNode for RecordField { 2384impl AstNode for RecordExprField {
2383 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD } 2385 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD }
2384 fn cast(syntax: SyntaxNode) -> Option<Self> { 2386 fn cast(syntax: SyntaxNode) -> Option<Self> {
2385 if Self::can_cast(syntax.kind()) { 2387 if Self::can_cast(syntax.kind()) {
2386 Some(Self { syntax }) 2388 Some(Self { syntax })
@@ -3119,8 +3121,8 @@ impl From<ReturnExpr> for Expr {
3119impl From<MatchExpr> for Expr { 3121impl From<MatchExpr> for Expr {
3120 fn from(node: MatchExpr) -> Expr { Expr::MatchExpr(node) } 3122 fn from(node: MatchExpr) -> Expr { Expr::MatchExpr(node) }
3121} 3123}
3122impl From<RecordLit> for Expr { 3124impl From<RecordExpr> for Expr {
3123 fn from(node: RecordLit) -> Expr { Expr::RecordLit(node) } 3125 fn from(node: RecordExpr) -> Expr { Expr::RecordExpr(node) }
3124} 3126}
3125impl From<CallExpr> for Expr { 3127impl From<CallExpr> for Expr {
3126 fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } 3128 fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) }
@@ -3172,7 +3174,7 @@ impl AstNode for Expr {
3172 match kind { 3174 match kind {
3173 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR 3175 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
3174 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL 3176 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
3175 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR 3177 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_EXPR | CALL_EXPR | INDEX_EXPR
3176 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | EFFECT_EXPR | CAST_EXPR 3178 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | EFFECT_EXPR | CAST_EXPR
3177 | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => { 3179 | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => {
3178 true 3180 true
@@ -3197,7 +3199,7 @@ impl AstNode for Expr {
3197 BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }), 3199 BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
3198 RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }), 3200 RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }),
3199 MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }), 3201 MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
3200 RECORD_LIT => Expr::RecordLit(RecordLit { syntax }), 3202 RECORD_EXPR => Expr::RecordExpr(RecordExpr { syntax }),
3201 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }), 3203 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
3202 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }), 3204 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
3203 METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }), 3205 METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
@@ -3234,7 +3236,7 @@ impl AstNode for Expr {
3234 Expr::BlockExpr(it) => &it.syntax, 3236 Expr::BlockExpr(it) => &it.syntax,
3235 Expr::ReturnExpr(it) => &it.syntax, 3237 Expr::ReturnExpr(it) => &it.syntax,
3236 Expr::MatchExpr(it) => &it.syntax, 3238 Expr::MatchExpr(it) => &it.syntax,
3237 Expr::RecordLit(it) => &it.syntax, 3239 Expr::RecordExpr(it) => &it.syntax,
3238 Expr::CallExpr(it) => &it.syntax, 3240 Expr::CallExpr(it) => &it.syntax,
3239 Expr::IndexExpr(it) => &it.syntax, 3241 Expr::IndexExpr(it) => &it.syntax,
3240 Expr::MethodCallExpr(it) => &it.syntax, 3242 Expr::MethodCallExpr(it) => &it.syntax,
@@ -3893,17 +3895,17 @@ impl std::fmt::Display for MatchGuard {
3893 std::fmt::Display::fmt(self.syntax(), f) 3895 std::fmt::Display::fmt(self.syntax(), f)
3894 } 3896 }
3895} 3897}
3896impl std::fmt::Display for RecordLit { 3898impl std::fmt::Display for RecordExpr {
3897 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3899 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3898 std::fmt::Display::fmt(self.syntax(), f) 3900 std::fmt::Display::fmt(self.syntax(), f)
3899 } 3901 }
3900} 3902}
3901impl std::fmt::Display for RecordFieldList { 3903impl std::fmt::Display for RecordExprFieldList {
3902 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3904 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3903 std::fmt::Display::fmt(self.syntax(), f) 3905 std::fmt::Display::fmt(self.syntax(), f)
3904 } 3906 }
3905} 3907}
3906impl std::fmt::Display for RecordField { 3908impl std::fmt::Display for RecordExprField {
3907 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3909 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3908 std::fmt::Display::fmt(self.syntax(), f) 3910 std::fmt::Display::fmt(self.syntax(), f)
3909 } 3911 }
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 4759f23a5..183ec4481 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -64,13 +64,13 @@ pub fn use_item(use_tree: ast::UseTree) -> ast::Use {
64 ast_from_text(&format!("use {};", use_tree)) 64 ast_from_text(&format!("use {};", use_tree))
65} 65}
66 66
67pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField { 67pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordExprField {
68 return match expr { 68 return match expr {
69 Some(expr) => from_text(&format!("{}: {}", name, expr)), 69 Some(expr) => from_text(&format!("{}: {}", name, expr)),
70 None => from_text(&name.to_string()), 70 None => from_text(&name.to_string()),
71 }; 71 };
72 72
73 fn from_text(text: &str) -> ast::RecordField { 73 fn from_text(text: &str) -> ast::RecordExprField {
74 ast_from_text(&format!("fn f() {{ S {{ {}, }} }}", text)) 74 ast_from_text(&format!("fn f() {{ S {{ {}, }} }}", text))
75 } 75 }
76} 76}
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs
index a7a301d6b..8c7457e32 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -189,11 +189,11 @@ impl ast::StructDef {
189 } 189 }
190} 190}
191 191
192impl ast::RecordField { 192impl ast::RecordExprField {
193 pub fn for_field_name(field_name: &ast::NameRef) -> Option<ast::RecordField> { 193 pub fn for_field_name(field_name: &ast::NameRef) -> Option<ast::RecordExprField> {
194 let candidate = 194 let candidate =
195 field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| { 195 field_name.syntax().parent().and_then(ast::RecordExprField::cast).or_else(|| {
196 field_name.syntax().ancestors().nth(4).and_then(ast::RecordField::cast) 196 field_name.syntax().ancestors().nth(4).and_then(ast::RecordExprField::cast)
197 })?; 197 })?;
198 if candidate.field_name().as_ref() == Some(field_name) { 198 if candidate.field_name().as_ref() == Some(field_name) {
199 Some(candidate) 199 Some(candidate)