diff options
author | Aleksey Kladov <[email protected]> | 2019-08-23 13:55:21 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-08-23 14:59:50 +0100 |
commit | 5b18a4eef9e69260ce2f105b33553c929cb7d827 (patch) | |
tree | 15f55b3eab48c3d0bbb1975fbd4db7cbb56d3e3e /crates/ra_hir/src | |
parent | c12dce0073c1766f7d2b10a69f8526a8093e70dc (diff) |
rename struct -> record, pos -> tuple
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/diagnostics.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 42 | ||||
-rw-r--r-- | crates/ra_hir/src/expr/validation.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 12 |
6 files changed, 45 insertions, 45 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 89fc1d1a1..66a58efed 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -318,8 +318,8 @@ pub struct StructField { | |||
318 | 318 | ||
319 | #[derive(Debug)] | 319 | #[derive(Debug)] |
320 | pub enum FieldSource { | 320 | pub enum FieldSource { |
321 | Named(ast::NamedFieldDef), | 321 | Named(ast::RecordFieldDef), |
322 | Pos(ast::PosFieldDef), | 322 | Pos(ast::TupleFieldDef), |
323 | } | 323 | } |
324 | 324 | ||
325 | impl StructField { | 325 | impl StructField { |
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index f6240830f..301109cb8 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs | |||
@@ -79,7 +79,7 @@ impl<'a> DiagnosticSink<'a> { | |||
79 | #[derive(Debug)] | 79 | #[derive(Debug)] |
80 | pub struct NoSuchField { | 80 | pub struct NoSuchField { |
81 | pub file: HirFileId, | 81 | pub file: HirFileId, |
82 | pub field: AstPtr<ast::NamedField>, | 82 | pub field: AstPtr<ast::RecordField>, |
83 | } | 83 | } |
84 | 84 | ||
85 | impl Diagnostic for NoSuchField { | 85 | impl Diagnostic for NoSuchField { |
@@ -118,7 +118,7 @@ impl Diagnostic for UnresolvedModule { | |||
118 | #[derive(Debug)] | 118 | #[derive(Debug)] |
119 | pub struct MissingFields { | 119 | pub struct MissingFields { |
120 | pub file: HirFileId, | 120 | pub file: HirFileId, |
121 | pub field_list: AstPtr<ast::NamedFieldList>, | 121 | pub field_list: AstPtr<ast::RecordFieldList>, |
122 | pub missed_fields: Vec<Name>, | 122 | pub missed_fields: Vec<Name>, |
123 | } | 123 | } |
124 | 124 | ||
@@ -135,11 +135,11 @@ impl Diagnostic for MissingFields { | |||
135 | } | 135 | } |
136 | 136 | ||
137 | impl AstDiagnostic for MissingFields { | 137 | impl AstDiagnostic for MissingFields { |
138 | type AST = ast::NamedFieldList; | 138 | type AST = ast::RecordFieldList; |
139 | 139 | ||
140 | fn ast(&self, db: &impl HirDatabase) -> Self::AST { | 140 | fn ast(&self, db: &impl HirDatabase) -> Self::AST { |
141 | let root = db.parse_or_expand(self.source().file_id).unwrap(); | 141 | let root = db.parse_or_expand(self.source().file_id).unwrap(); |
142 | let node = self.source().ast.to_node(&root); | 142 | let node = self.source().ast.to_node(&root); |
143 | ast::NamedFieldList::cast(node).unwrap() | 143 | ast::RecordFieldList::cast(node).unwrap() |
144 | } | 144 | } |
145 | } | 145 | } |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 328d635d4..9e8584908 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -60,7 +60,7 @@ pub struct BodySourceMap { | |||
60 | expr_map_back: ArenaMap<ExprId, SyntaxNodePtr>, | 60 | expr_map_back: ArenaMap<ExprId, SyntaxNodePtr>, |
61 | pat_map: FxHashMap<PatPtr, PatId>, | 61 | pat_map: FxHashMap<PatPtr, PatId>, |
62 | pat_map_back: ArenaMap<PatId, PatPtr>, | 62 | pat_map_back: ArenaMap<PatId, PatPtr>, |
63 | field_map: FxHashMap<(ExprId, usize), AstPtr<ast::NamedField>>, | 63 | field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>, |
64 | } | 64 | } |
65 | 65 | ||
66 | type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; | 66 | type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; |
@@ -148,7 +148,7 @@ impl BodySourceMap { | |||
148 | self.pat_map.get(&Either::A(AstPtr::new(node))).cloned() | 148 | self.pat_map.get(&Either::A(AstPtr::new(node))).cloned() |
149 | } | 149 | } |
150 | 150 | ||
151 | pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::NamedField> { | 151 | pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { |
152 | self.field_map[&(expr, field)] | 152 | self.field_map[&(expr, field)] |
153 | } | 153 | } |
154 | } | 154 | } |
@@ -210,9 +210,9 @@ pub enum Expr { | |||
210 | Return { | 210 | Return { |
211 | expr: Option<ExprId>, | 211 | expr: Option<ExprId>, |
212 | }, | 212 | }, |
213 | StructLit { | 213 | RecordLit { |
214 | path: Option<Path>, | 214 | path: Option<Path>, |
215 | fields: Vec<StructLitField>, | 215 | fields: Vec<RecordLitField>, |
216 | spread: Option<ExprId>, | 216 | spread: Option<ExprId>, |
217 | }, | 217 | }, |
218 | Field { | 218 | Field { |
@@ -316,7 +316,7 @@ pub struct MatchArm { | |||
316 | } | 316 | } |
317 | 317 | ||
318 | #[derive(Debug, Clone, Eq, PartialEq)] | 318 | #[derive(Debug, Clone, Eq, PartialEq)] |
319 | pub struct StructLitField { | 319 | pub struct RecordLitField { |
320 | pub name: Name, | 320 | pub name: Name, |
321 | pub expr: ExprId, | 321 | pub expr: ExprId, |
322 | } | 322 | } |
@@ -388,7 +388,7 @@ impl Expr { | |||
388 | f(*expr); | 388 | f(*expr); |
389 | } | 389 | } |
390 | } | 390 | } |
391 | Expr::StructLit { fields, spread, .. } => { | 391 | Expr::RecordLit { fields, spread, .. } => { |
392 | for field in fields { | 392 | for field in fields { |
393 | f(field.expr); | 393 | f(field.expr); |
394 | } | 394 | } |
@@ -474,7 +474,7 @@ impl BindingAnnotation { | |||
474 | } | 474 | } |
475 | 475 | ||
476 | #[derive(Debug, Clone, Eq, PartialEq)] | 476 | #[derive(Debug, Clone, Eq, PartialEq)] |
477 | pub struct FieldPat { | 477 | pub struct RecordFieldPat { |
478 | pub(crate) name: Name, | 478 | pub(crate) name: Name, |
479 | pub(crate) pat: PatId, | 479 | pub(crate) pat: PatId, |
480 | } | 480 | } |
@@ -487,7 +487,7 @@ pub enum Pat { | |||
487 | Tuple(Vec<PatId>), | 487 | Tuple(Vec<PatId>), |
488 | Struct { | 488 | Struct { |
489 | path: Option<Path>, | 489 | path: Option<Path>, |
490 | args: Vec<FieldPat>, | 490 | args: Vec<RecordFieldPat>, |
491 | // FIXME: 'ellipsis' option | 491 | // FIXME: 'ellipsis' option |
492 | }, | 492 | }, |
493 | Range { | 493 | Range { |
@@ -746,14 +746,14 @@ where | |||
746 | let expr = e.expr().map(|e| self.collect_expr(e)); | 746 | let expr = e.expr().map(|e| self.collect_expr(e)); |
747 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) | 747 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) |
748 | } | 748 | } |
749 | ast::Expr::StructLit(e) => { | 749 | ast::Expr::RecordLit(e) => { |
750 | let path = e.path().and_then(Path::from_ast); | 750 | let path = e.path().and_then(Path::from_ast); |
751 | let mut field_ptrs = Vec::new(); | 751 | let mut field_ptrs = Vec::new(); |
752 | let struct_lit = if let Some(nfl) = e.named_field_list() { | 752 | let record_lit = if let Some(nfl) = e.record_field_list() { |
753 | let fields = nfl | 753 | let fields = nfl |
754 | .fields() | 754 | .fields() |
755 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) | 755 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) |
756 | .map(|field| StructLitField { | 756 | .map(|field| RecordLitField { |
757 | name: field | 757 | name: field |
758 | .name_ref() | 758 | .name_ref() |
759 | .map(|nr| nr.as_name()) | 759 | .map(|nr| nr.as_name()) |
@@ -776,12 +776,12 @@ where | |||
776 | }) | 776 | }) |
777 | .collect(); | 777 | .collect(); |
778 | let spread = nfl.spread().map(|s| self.collect_expr(s)); | 778 | let spread = nfl.spread().map(|s| self.collect_expr(s)); |
779 | Expr::StructLit { path, fields, spread } | 779 | Expr::RecordLit { path, fields, spread } |
780 | } else { | 780 | } else { |
781 | Expr::StructLit { path, fields: Vec::new(), spread: None } | 781 | Expr::RecordLit { path, fields: Vec::new(), spread: None } |
782 | }; | 782 | }; |
783 | 783 | ||
784 | let res = self.alloc_expr(struct_lit, syntax_ptr); | 784 | let res = self.alloc_expr(record_lit, syntax_ptr); |
785 | for (i, ptr) in field_ptrs.into_iter().enumerate() { | 785 | for (i, ptr) in field_ptrs.into_iter().enumerate() { |
786 | self.source_map.field_map.insert((res, i), ptr); | 786 | self.source_map.field_map.insert((res, i), ptr); |
787 | } | 787 | } |
@@ -994,25 +994,25 @@ where | |||
994 | Pat::Tuple(args) | 994 | Pat::Tuple(args) |
995 | } | 995 | } |
996 | ast::Pat::PlaceholderPat(_) => Pat::Wild, | 996 | ast::Pat::PlaceholderPat(_) => Pat::Wild, |
997 | ast::Pat::StructPat(p) => { | 997 | ast::Pat::RecordPat(p) => { |
998 | let path = p.path().and_then(Path::from_ast); | 998 | let path = p.path().and_then(Path::from_ast); |
999 | let field_pat_list = | 999 | let record_field_pat_list = |
1000 | p.field_pat_list().expect("every struct should have a field list"); | 1000 | p.record_field_pat_list().expect("every struct should have a field list"); |
1001 | let mut fields: Vec<_> = field_pat_list | 1001 | let mut fields: Vec<_> = record_field_pat_list |
1002 | .bind_pats() | 1002 | .bind_pats() |
1003 | .filter_map(|bind_pat| { | 1003 | .filter_map(|bind_pat| { |
1004 | let ast_pat = | 1004 | let ast_pat = |
1005 | ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat"); | 1005 | ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat"); |
1006 | let pat = self.collect_pat(ast_pat); | 1006 | let pat = self.collect_pat(ast_pat); |
1007 | let name = bind_pat.name()?.as_name(); | 1007 | let name = bind_pat.name()?.as_name(); |
1008 | Some(FieldPat { name, pat }) | 1008 | Some(RecordFieldPat { name, pat }) |
1009 | }) | 1009 | }) |
1010 | .collect(); | 1010 | .collect(); |
1011 | let iter = field_pat_list.field_pats().filter_map(|f| { | 1011 | let iter = record_field_pat_list.record_field_pats().filter_map(|f| { |
1012 | let ast_pat = f.pat()?; | 1012 | let ast_pat = f.pat()?; |
1013 | let pat = self.collect_pat(ast_pat); | 1013 | let pat = self.collect_pat(ast_pat); |
1014 | let name = f.name()?.as_name(); | 1014 | let name = f.name()?.as_name(); |
1015 | Some(FieldPat { name, pat }) | 1015 | Some(RecordFieldPat { name, pat }) |
1016 | }); | 1016 | }); |
1017 | fields.extend(iter); | 1017 | fields.extend(iter); |
1018 | 1018 | ||
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index 82a06ca25..62f7d41f5 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use ra_syntax::ast::{AstNode, StructLit}; | 4 | use ra_syntax::ast::{AstNode, RecordLit}; |
5 | 5 | ||
6 | use super::{Expr, ExprId, StructLitField}; | 6 | use super::{Expr, ExprId, RecordLitField}; |
7 | use crate::{ | 7 | use crate::{ |
8 | adt::AdtDef, | 8 | adt::AdtDef, |
9 | diagnostics::{DiagnosticSink, MissingFields}, | 9 | diagnostics::{DiagnosticSink, MissingFields}, |
@@ -30,17 +30,17 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
30 | pub(crate) fn validate_body(&mut self, db: &impl HirDatabase) { | 30 | pub(crate) fn validate_body(&mut self, db: &impl HirDatabase) { |
31 | let body = self.func.body(db); | 31 | let body = self.func.body(db); |
32 | for e in body.exprs() { | 32 | for e in body.exprs() { |
33 | if let (id, Expr::StructLit { path, fields, spread }) = e { | 33 | if let (id, Expr::RecordLit { path, fields, spread }) = e { |
34 | self.validate_struct_literal(id, path, fields, *spread, db); | 34 | self.validate_record_literal(id, path, fields, *spread, db); |
35 | } | 35 | } |
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | fn validate_struct_literal( | 39 | fn validate_record_literal( |
40 | &mut self, | 40 | &mut self, |
41 | id: ExprId, | 41 | id: ExprId, |
42 | _path: &Option<Path>, | 42 | _path: &Option<Path>, |
43 | fields: &[StructLitField], | 43 | fields: &[RecordLitField], |
44 | spread: Option<ExprId>, | 44 | spread: Option<ExprId>, |
45 | db: &impl HirDatabase, | 45 | db: &impl HirDatabase, |
46 | ) { | 46 | ) { |
@@ -76,8 +76,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
76 | if let Some(field_list_node) = source_map | 76 | if let Some(field_list_node) = source_map |
77 | .expr_syntax(id) | 77 | .expr_syntax(id) |
78 | .map(|ptr| ptr.to_node(source_file.syntax())) | 78 | .map(|ptr| ptr.to_node(source_file.syntax())) |
79 | .and_then(StructLit::cast) | 79 | .and_then(RecordLit::cast) |
80 | .and_then(|lit| lit.named_field_list()) | 80 | .and_then(|lit| lit.record_field_list()) |
81 | { | 81 | { |
82 | let field_list_ptr = AstPtr::new(&field_list_node); | 82 | let field_list_ptr = AstPtr::new(&field_list_node); |
83 | self.sink.push(MissingFields { | 83 | self.sink.push(MissingFields { |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index e86716d74..56ff7da3a 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -278,13 +278,13 @@ impl SourceAnalyzer { | |||
278 | self.infer.as_ref()?.field_resolution(expr_id) | 278 | self.infer.as_ref()?.field_resolution(expr_id) |
279 | } | 279 | } |
280 | 280 | ||
281 | pub fn resolve_struct_literal(&self, struct_lit: &ast::StructLit) -> Option<crate::VariantDef> { | 281 | pub fn resolve_record_literal(&self, record_lit: &ast::RecordLit) -> Option<crate::VariantDef> { |
282 | let expr_id = self.body_source_map.as_ref()?.node_expr(&struct_lit.clone().into())?; | 282 | let expr_id = self.body_source_map.as_ref()?.node_expr(&record_lit.clone().into())?; |
283 | self.infer.as_ref()?.variant_resolution_for_expr(expr_id) | 283 | self.infer.as_ref()?.variant_resolution_for_expr(expr_id) |
284 | } | 284 | } |
285 | 285 | ||
286 | pub fn resolve_struct_pattern(&self, struct_pat: &ast::StructPat) -> Option<crate::VariantDef> { | 286 | pub fn resolve_record_pattern(&self, record_pat: &ast::RecordPat) -> Option<crate::VariantDef> { |
287 | let pat_id = self.body_source_map.as_ref()?.node_pat(&struct_pat.clone().into())?; | 287 | let pat_id = self.body_source_map.as_ref()?.node_pat(&record_pat.clone().into())?; |
288 | self.infer.as_ref()?.variant_resolution_for_pat(pat_id) | 288 | self.infer.as_ref()?.variant_resolution_for_pat(pat_id) |
289 | } | 289 | } |
290 | 290 | ||
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index cca59538a..b33de5687 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -37,8 +37,8 @@ use crate::{ | |||
37 | code_model::{ModuleDef::Trait, TypeAlias}, | 37 | code_model::{ModuleDef::Trait, TypeAlias}, |
38 | diagnostics::DiagnosticSink, | 38 | diagnostics::DiagnosticSink, |
39 | expr::{ | 39 | expr::{ |
40 | self, Array, BinaryOp, BindingAnnotation, Body, Expr, ExprId, FieldPat, Literal, Pat, | 40 | self, Array, BinaryOp, BindingAnnotation, Body, Expr, ExprId, Literal, Pat, PatId, |
41 | PatId, Statement, UnaryOp, | 41 | RecordFieldPat, Statement, UnaryOp, |
42 | }, | 42 | }, |
43 | generics::{GenericParams, HasGenericParams}, | 43 | generics::{GenericParams, HasGenericParams}, |
44 | name, | 44 | name, |
@@ -705,10 +705,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
705 | ty | 705 | ty |
706 | } | 706 | } |
707 | 707 | ||
708 | fn infer_struct_pat( | 708 | fn infer_record_pat( |
709 | &mut self, | 709 | &mut self, |
710 | path: Option<&Path>, | 710 | path: Option<&Path>, |
711 | subpats: &[FieldPat], | 711 | subpats: &[RecordFieldPat], |
712 | expected: &Ty, | 712 | expected: &Ty, |
713 | default_bm: BindingMode, | 713 | default_bm: BindingMode, |
714 | id: PatId, | 714 | id: PatId, |
@@ -800,7 +800,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
800 | self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) | 800 | self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) |
801 | } | 801 | } |
802 | Pat::Struct { path: ref p, args: ref fields } => { | 802 | Pat::Struct { path: ref p, args: ref fields } => { |
803 | self.infer_struct_pat(p.as_ref(), fields, expected, default_bm, pat) | 803 | self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat) |
804 | } | 804 | } |
805 | Pat::Path(path) => { | 805 | Pat::Path(path) => { |
806 | // FIXME use correct resolver for the surrounding expression | 806 | // FIXME use correct resolver for the surrounding expression |
@@ -1103,7 +1103,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1103 | } | 1103 | } |
1104 | Ty::simple(TypeCtor::Never) | 1104 | Ty::simple(TypeCtor::Never) |
1105 | } | 1105 | } |
1106 | Expr::StructLit { path, fields, spread } => { | 1106 | Expr::RecordLit { path, fields, spread } => { |
1107 | let (ty, def_id) = self.resolve_variant(path.as_ref()); | 1107 | let (ty, def_id) = self.resolve_variant(path.as_ref()); |
1108 | if let Some(variant) = def_id { | 1108 | if let Some(variant) = def_id { |
1109 | self.write_variant_resolution(tgt_expr.into(), variant); | 1109 | self.write_variant_resolution(tgt_expr.into(), variant); |