From 5b18a4eef9e69260ce2f105b33553c929cb7d827 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 23 Aug 2019 15:55:21 +0300 Subject: rename struct -> record, pos -> tuple --- crates/ra_hir/src/code_model.rs | 4 ++-- crates/ra_hir/src/diagnostics.rs | 8 +++---- crates/ra_hir/src/expr.rs | 42 ++++++++++++++++++------------------ crates/ra_hir/src/expr/validation.rs | 16 +++++++------- crates/ra_hir/src/source_binder.rs | 8 +++---- crates/ra_hir/src/ty/infer.rs | 12 +++++------ 6 files changed, 45 insertions(+), 45 deletions(-) (limited to 'crates/ra_hir/src') 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 { #[derive(Debug)] pub enum FieldSource { - Named(ast::NamedFieldDef), - Pos(ast::PosFieldDef), + Named(ast::RecordFieldDef), + Pos(ast::TupleFieldDef), } 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> { #[derive(Debug)] pub struct NoSuchField { pub file: HirFileId, - pub field: AstPtr, + pub field: AstPtr, } impl Diagnostic for NoSuchField { @@ -118,7 +118,7 @@ impl Diagnostic for UnresolvedModule { #[derive(Debug)] pub struct MissingFields { pub file: HirFileId, - pub field_list: AstPtr, + pub field_list: AstPtr, pub missed_fields: Vec, } @@ -135,11 +135,11 @@ impl Diagnostic for MissingFields { } impl AstDiagnostic for MissingFields { - type AST = ast::NamedFieldList; + type AST = ast::RecordFieldList; fn ast(&self, db: &impl HirDatabase) -> Self::AST { let root = db.parse_or_expand(self.source().file_id).unwrap(); let node = self.source().ast.to_node(&root); - ast::NamedFieldList::cast(node).unwrap() + ast::RecordFieldList::cast(node).unwrap() } } 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 { expr_map_back: ArenaMap, pat_map: FxHashMap, pat_map_back: ArenaMap, - field_map: FxHashMap<(ExprId, usize), AstPtr>, + field_map: FxHashMap<(ExprId, usize), AstPtr>, } type PatPtr = Either, AstPtr>; @@ -148,7 +148,7 @@ impl BodySourceMap { self.pat_map.get(&Either::A(AstPtr::new(node))).cloned() } - pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr { + pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr { self.field_map[&(expr, field)] } } @@ -210,9 +210,9 @@ pub enum Expr { Return { expr: Option, }, - StructLit { + RecordLit { path: Option, - fields: Vec, + fields: Vec, spread: Option, }, Field { @@ -316,7 +316,7 @@ pub struct MatchArm { } #[derive(Debug, Clone, Eq, PartialEq)] -pub struct StructLitField { +pub struct RecordLitField { pub name: Name, pub expr: ExprId, } @@ -388,7 +388,7 @@ impl Expr { f(*expr); } } - Expr::StructLit { fields, spread, .. } => { + Expr::RecordLit { fields, spread, .. } => { for field in fields { f(field.expr); } @@ -474,7 +474,7 @@ impl BindingAnnotation { } #[derive(Debug, Clone, Eq, PartialEq)] -pub struct FieldPat { +pub struct RecordFieldPat { pub(crate) name: Name, pub(crate) pat: PatId, } @@ -487,7 +487,7 @@ pub enum Pat { Tuple(Vec), Struct { path: Option, - args: Vec, + args: Vec, // FIXME: 'ellipsis' option }, Range { @@ -746,14 +746,14 @@ where let expr = e.expr().map(|e| self.collect_expr(e)); self.alloc_expr(Expr::Return { expr }, syntax_ptr) } - ast::Expr::StructLit(e) => { + ast::Expr::RecordLit(e) => { let path = e.path().and_then(Path::from_ast); let mut field_ptrs = Vec::new(); - let struct_lit = if let Some(nfl) = e.named_field_list() { + let record_lit = if let Some(nfl) = e.record_field_list() { let fields = nfl .fields() .inspect(|field| field_ptrs.push(AstPtr::new(field))) - .map(|field| StructLitField { + .map(|field| RecordLitField { name: field .name_ref() .map(|nr| nr.as_name()) @@ -776,12 +776,12 @@ where }) .collect(); let spread = nfl.spread().map(|s| self.collect_expr(s)); - Expr::StructLit { path, fields, spread } + Expr::RecordLit { path, fields, spread } } else { - Expr::StructLit { path, fields: Vec::new(), spread: None } + Expr::RecordLit { path, fields: Vec::new(), spread: None } }; - let res = self.alloc_expr(struct_lit, syntax_ptr); + let res = self.alloc_expr(record_lit, syntax_ptr); for (i, ptr) in field_ptrs.into_iter().enumerate() { self.source_map.field_map.insert((res, i), ptr); } @@ -994,25 +994,25 @@ where Pat::Tuple(args) } ast::Pat::PlaceholderPat(_) => Pat::Wild, - ast::Pat::StructPat(p) => { + ast::Pat::RecordPat(p) => { let path = p.path().and_then(Path::from_ast); - let field_pat_list = - p.field_pat_list().expect("every struct should have a field list"); - let mut fields: Vec<_> = field_pat_list + let record_field_pat_list = + p.record_field_pat_list().expect("every struct should have a field list"); + let mut fields: Vec<_> = record_field_pat_list .bind_pats() .filter_map(|bind_pat| { let ast_pat = ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat"); let pat = self.collect_pat(ast_pat); let name = bind_pat.name()?.as_name(); - Some(FieldPat { name, pat }) + Some(RecordFieldPat { name, pat }) }) .collect(); - let iter = field_pat_list.field_pats().filter_map(|f| { + let iter = record_field_pat_list.record_field_pats().filter_map(|f| { let ast_pat = f.pat()?; let pat = self.collect_pat(ast_pat); let name = f.name()?.as_name(); - Some(FieldPat { name, pat }) + Some(RecordFieldPat { name, pat }) }); fields.extend(iter); 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 @@ use rustc_hash::FxHashSet; use std::sync::Arc; -use ra_syntax::ast::{AstNode, StructLit}; +use ra_syntax::ast::{AstNode, RecordLit}; -use super::{Expr, ExprId, StructLitField}; +use super::{Expr, ExprId, RecordLitField}; use crate::{ adt::AdtDef, diagnostics::{DiagnosticSink, MissingFields}, @@ -30,17 +30,17 @@ impl<'a, 'b> ExprValidator<'a, 'b> { pub(crate) fn validate_body(&mut self, db: &impl HirDatabase) { let body = self.func.body(db); for e in body.exprs() { - if let (id, Expr::StructLit { path, fields, spread }) = e { - self.validate_struct_literal(id, path, fields, *spread, db); + if let (id, Expr::RecordLit { path, fields, spread }) = e { + self.validate_record_literal(id, path, fields, *spread, db); } } } - fn validate_struct_literal( + fn validate_record_literal( &mut self, id: ExprId, _path: &Option, - fields: &[StructLitField], + fields: &[RecordLitField], spread: Option, db: &impl HirDatabase, ) { @@ -76,8 +76,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> { if let Some(field_list_node) = source_map .expr_syntax(id) .map(|ptr| ptr.to_node(source_file.syntax())) - .and_then(StructLit::cast) - .and_then(|lit| lit.named_field_list()) + .and_then(RecordLit::cast) + .and_then(|lit| lit.record_field_list()) { let field_list_ptr = AstPtr::new(&field_list_node); 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 { self.infer.as_ref()?.field_resolution(expr_id) } - pub fn resolve_struct_literal(&self, struct_lit: &ast::StructLit) -> Option { - let expr_id = self.body_source_map.as_ref()?.node_expr(&struct_lit.clone().into())?; + pub fn resolve_record_literal(&self, record_lit: &ast::RecordLit) -> Option { + let expr_id = self.body_source_map.as_ref()?.node_expr(&record_lit.clone().into())?; self.infer.as_ref()?.variant_resolution_for_expr(expr_id) } - pub fn resolve_struct_pattern(&self, struct_pat: &ast::StructPat) -> Option { - let pat_id = self.body_source_map.as_ref()?.node_pat(&struct_pat.clone().into())?; + pub fn resolve_record_pattern(&self, record_pat: &ast::RecordPat) -> Option { + let pat_id = self.body_source_map.as_ref()?.node_pat(&record_pat.clone().into())?; self.infer.as_ref()?.variant_resolution_for_pat(pat_id) } 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::{ code_model::{ModuleDef::Trait, TypeAlias}, diagnostics::DiagnosticSink, expr::{ - self, Array, BinaryOp, BindingAnnotation, Body, Expr, ExprId, FieldPat, Literal, Pat, - PatId, Statement, UnaryOp, + self, Array, BinaryOp, BindingAnnotation, Body, Expr, ExprId, Literal, Pat, PatId, + RecordFieldPat, Statement, UnaryOp, }, generics::{GenericParams, HasGenericParams}, name, @@ -705,10 +705,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { ty } - fn infer_struct_pat( + fn infer_record_pat( &mut self, path: Option<&Path>, - subpats: &[FieldPat], + subpats: &[RecordFieldPat], expected: &Ty, default_bm: BindingMode, id: PatId, @@ -800,7 +800,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) } Pat::Struct { path: ref p, args: ref fields } => { - self.infer_struct_pat(p.as_ref(), fields, expected, default_bm, pat) + self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat) } Pat::Path(path) => { // FIXME use correct resolver for the surrounding expression @@ -1103,7 +1103,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } Ty::simple(TypeCtor::Never) } - Expr::StructLit { path, fields, spread } => { + Expr::RecordLit { path, fields, spread } => { let (ty, def_id) = self.resolve_variant(path.as_ref()); if let Some(variant) = def_id { self.write_variant_resolution(tgt_expr.into(), variant); -- cgit v1.2.3