Skip to content

Commit a832a2f

Browse files
bors[bot]matklad
andauthored
Merge #1731
1731: rename pos_field -> tuple_field r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents c12dce0 + 5b18a4e commit a832a2f

File tree

78 files changed

+598
-592
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+598
-592
lines changed

crates/ra_assists/src/ast_editor.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ impl<N: AstNode> AstEditor<N> {
9393
}
9494
}
9595

96-
impl AstEditor<ast::NamedFieldList> {
97-
pub fn append_field(&mut self, field: &ast::NamedField) {
96+
impl AstEditor<ast::RecordFieldList> {
97+
pub fn append_field(&mut self, field: &ast::RecordField) {
9898
self.insert_field(InsertPosition::Last, field)
9999
}
100100

101101
pub fn insert_field(
102102
&mut self,
103-
position: InsertPosition<&'_ ast::NamedField>,
104-
field: &ast::NamedField,
103+
position: InsertPosition<&'_ ast::RecordField>,
104+
field: &ast::RecordField,
105105
) {
106106
let is_multiline = self.ast().syntax().text().contains_char('\n');
107107
let ws;
@@ -245,16 +245,16 @@ pub struct AstBuilder<N: AstNode> {
245245
_phantom: std::marker::PhantomData<N>,
246246
}
247247

248-
impl AstBuilder<ast::NamedField> {
249-
pub fn from_name(name: &Name) -> ast::NamedField {
248+
impl AstBuilder<ast::RecordField> {
249+
pub fn from_name(name: &Name) -> ast::RecordField {
250250
ast_node_from_file_text(&format!("fn f() {{ S {{ {}: (), }} }}", name))
251251
}
252252

253-
fn from_text(text: &str) -> ast::NamedField {
253+
fn from_text(text: &str) -> ast::RecordField {
254254
ast_node_from_file_text(&format!("fn f() {{ S {{ {}, }} }}", text))
255255
}
256256

257-
pub fn from_pieces(name: &ast::NameRef, expr: Option<&ast::Expr>) -> ast::NamedField {
257+
pub fn from_pieces(name: &ast::NameRef, expr: Option<&ast::Expr>) -> ast::RecordField {
258258
match expr {
259259
Some(expr) => Self::from_text(&format!("{}: {}", name.syntax(), expr.syntax())),
260260
None => Self::from_text(&name.syntax().to_string()),
@@ -336,12 +336,12 @@ impl AstBuilder<ast::TupleStructPat> {
336336
}
337337
}
338338

339-
impl AstBuilder<ast::StructPat> {
340-
fn from_text(text: &str) -> ast::StructPat {
339+
impl AstBuilder<ast::RecordPat> {
340+
fn from_text(text: &str) -> ast::RecordPat {
341341
ast_node_from_file_text(&format!("fn f({}: ())", text))
342342
}
343343

344-
pub fn from_pieces(path: &ast::Path, pats: impl Iterator<Item = ast::Pat>) -> ast::StructPat {
344+
pub fn from_pieces(path: &ast::Path, pats: impl Iterator<Item = ast::Pat>) -> ast::RecordPat {
345345
let pats_str = pats.map(|p| p.syntax().to_string()).collect::<Vec<_>>().join(", ");
346346
Self::from_text(&format!("{}{{ {} }}", path.syntax(), pats_str))
347347
}

crates/ra_assists/src/change_visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn add_vis(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
3838
(vis_offset(&parent), keyword.text_range())
3939
} else {
4040
let ident = ctx.token_at_offset().find(|leaf| leaf.kind() == IDENT)?;
41-
let field = ident.parent().ancestors().find_map(ast::NamedFieldDef::cast)?;
41+
let field = ident.parent().ancestors().find_map(ast::RecordFieldDef::cast)?;
4242
if field.name()?.syntax().text_range() != ident.text_range() && field.visibility().is_some()
4343
{
4444
return None;

crates/ra_assists/src/fill_match_arms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn build_pat(var: ast::EnumVariant) -> Option<ast::Pat> {
7878
let pats = field_list
7979
.fields()
8080
.map(|f| AstBuilder::<ast::BindPat>::from_name(&f.name().unwrap()).into());
81-
AstBuilder::<ast::StructPat>::from_pieces(path, pats).into()
81+
AstBuilder::<ast::RecordPat>::from_pieces(path, pats).into()
8282
}
8383
ast::StructKind::Unit => AstBuilder::<ast::PathPat>::from_path(path).into(),
8484
};

crates/ra_hir/src/code_model.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ pub struct StructField {
318318

319319
#[derive(Debug)]
320320
pub enum FieldSource {
321-
Named(ast::NamedFieldDef),
322-
Pos(ast::PosFieldDef),
321+
Named(ast::RecordFieldDef),
322+
Pos(ast::TupleFieldDef),
323323
}
324324

325325
impl StructField {

crates/ra_hir/src/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a> DiagnosticSink<'a> {
7979
#[derive(Debug)]
8080
pub struct NoSuchField {
8181
pub file: HirFileId,
82-
pub field: AstPtr<ast::NamedField>,
82+
pub field: AstPtr<ast::RecordField>,
8383
}
8484

8585
impl Diagnostic for NoSuchField {
@@ -118,7 +118,7 @@ impl Diagnostic for UnresolvedModule {
118118
#[derive(Debug)]
119119
pub struct MissingFields {
120120
pub file: HirFileId,
121-
pub field_list: AstPtr<ast::NamedFieldList>,
121+
pub field_list: AstPtr<ast::RecordFieldList>,
122122
pub missed_fields: Vec<Name>,
123123
}
124124

@@ -135,11 +135,11 @@ impl Diagnostic for MissingFields {
135135
}
136136

137137
impl AstDiagnostic for MissingFields {
138-
type AST = ast::NamedFieldList;
138+
type AST = ast::RecordFieldList;
139139

140140
fn ast(&self, db: &impl HirDatabase) -> Self::AST {
141141
let root = db.parse_or_expand(self.source().file_id).unwrap();
142142
let node = self.source().ast.to_node(&root);
143-
ast::NamedFieldList::cast(node).unwrap()
143+
ast::RecordFieldList::cast(node).unwrap()
144144
}
145145
}

crates/ra_hir/src/expr.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub struct BodySourceMap {
6060
expr_map_back: ArenaMap<ExprId, SyntaxNodePtr>,
6161
pat_map: FxHashMap<PatPtr, PatId>,
6262
pat_map_back: ArenaMap<PatId, PatPtr>,
63-
field_map: FxHashMap<(ExprId, usize), AstPtr<ast::NamedField>>,
63+
field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>,
6464
}
6565

6666
type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>;
@@ -148,7 +148,7 @@ impl BodySourceMap {
148148
self.pat_map.get(&Either::A(AstPtr::new(node))).cloned()
149149
}
150150

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> {
152152
self.field_map[&(expr, field)]
153153
}
154154
}
@@ -210,9 +210,9 @@ pub enum Expr {
210210
Return {
211211
expr: Option<ExprId>,
212212
},
213-
StructLit {
213+
RecordLit {
214214
path: Option<Path>,
215-
fields: Vec<StructLitField>,
215+
fields: Vec<RecordLitField>,
216216
spread: Option<ExprId>,
217217
},
218218
Field {
@@ -316,7 +316,7 @@ pub struct MatchArm {
316316
}
317317

318318
#[derive(Debug, Clone, Eq, PartialEq)]
319-
pub struct StructLitField {
319+
pub struct RecordLitField {
320320
pub name: Name,
321321
pub expr: ExprId,
322322
}
@@ -388,7 +388,7 @@ impl Expr {
388388
f(*expr);
389389
}
390390
}
391-
Expr::StructLit { fields, spread, .. } => {
391+
Expr::RecordLit { fields, spread, .. } => {
392392
for field in fields {
393393
f(field.expr);
394394
}
@@ -474,7 +474,7 @@ impl BindingAnnotation {
474474
}
475475

476476
#[derive(Debug, Clone, Eq, PartialEq)]
477-
pub struct FieldPat {
477+
pub struct RecordFieldPat {
478478
pub(crate) name: Name,
479479
pub(crate) pat: PatId,
480480
}
@@ -487,7 +487,7 @@ pub enum Pat {
487487
Tuple(Vec<PatId>),
488488
Struct {
489489
path: Option<Path>,
490-
args: Vec<FieldPat>,
490+
args: Vec<RecordFieldPat>,
491491
// FIXME: 'ellipsis' option
492492
},
493493
Range {
@@ -746,14 +746,14 @@ where
746746
let expr = e.expr().map(|e| self.collect_expr(e));
747747
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
748748
}
749-
ast::Expr::StructLit(e) => {
749+
ast::Expr::RecordLit(e) => {
750750
let path = e.path().and_then(Path::from_ast);
751751
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() {
753753
let fields = nfl
754754
.fields()
755755
.inspect(|field| field_ptrs.push(AstPtr::new(field)))
756-
.map(|field| StructLitField {
756+
.map(|field| RecordLitField {
757757
name: field
758758
.name_ref()
759759
.map(|nr| nr.as_name())
@@ -776,12 +776,12 @@ where
776776
})
777777
.collect();
778778
let spread = nfl.spread().map(|s| self.collect_expr(s));
779-
Expr::StructLit { path, fields, spread }
779+
Expr::RecordLit { path, fields, spread }
780780
} else {
781-
Expr::StructLit { path, fields: Vec::new(), spread: None }
781+
Expr::RecordLit { path, fields: Vec::new(), spread: None }
782782
};
783783

784-
let res = self.alloc_expr(struct_lit, syntax_ptr);
784+
let res = self.alloc_expr(record_lit, syntax_ptr);
785785
for (i, ptr) in field_ptrs.into_iter().enumerate() {
786786
self.source_map.field_map.insert((res, i), ptr);
787787
}
@@ -994,25 +994,25 @@ where
994994
Pat::Tuple(args)
995995
}
996996
ast::Pat::PlaceholderPat(_) => Pat::Wild,
997-
ast::Pat::StructPat(p) => {
997+
ast::Pat::RecordPat(p) => {
998998
let path = p.path().and_then(Path::from_ast);
999-
let field_pat_list =
1000-
p.field_pat_list().expect("every struct should have a field list");
1001-
let mut fields: Vec<_> = field_pat_list
999+
let record_field_pat_list =
1000+
p.record_field_pat_list().expect("every struct should have a field list");
1001+
let mut fields: Vec<_> = record_field_pat_list
10021002
.bind_pats()
10031003
.filter_map(|bind_pat| {
10041004
let ast_pat =
10051005
ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat");
10061006
let pat = self.collect_pat(ast_pat);
10071007
let name = bind_pat.name()?.as_name();
1008-
Some(FieldPat { name, pat })
1008+
Some(RecordFieldPat { name, pat })
10091009
})
10101010
.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| {
10121012
let ast_pat = f.pat()?;
10131013
let pat = self.collect_pat(ast_pat);
10141014
let name = f.name()?.as_name();
1015-
Some(FieldPat { name, pat })
1015+
Some(RecordFieldPat { name, pat })
10161016
});
10171017
fields.extend(iter);
10181018

crates/ra_hir/src/expr/validation.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use rustc_hash::FxHashSet;
22
use std::sync::Arc;
33

4-
use ra_syntax::ast::{AstNode, StructLit};
4+
use ra_syntax::ast::{AstNode, RecordLit};
55

6-
use super::{Expr, ExprId, StructLitField};
6+
use super::{Expr, ExprId, RecordLitField};
77
use crate::{
88
adt::AdtDef,
99
diagnostics::{DiagnosticSink, MissingFields},
@@ -30,17 +30,17 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
3030
pub(crate) fn validate_body(&mut self, db: &impl HirDatabase) {
3131
let body = self.func.body(db);
3232
for e in body.exprs() {
33-
if let (id, Expr::StructLit { path, fields, spread }) = e {
34-
self.validate_struct_literal(id, path, fields, *spread, db);
33+
if let (id, Expr::RecordLit { path, fields, spread }) = e {
34+
self.validate_record_literal(id, path, fields, *spread, db);
3535
}
3636
}
3737
}
3838

39-
fn validate_struct_literal(
39+
fn validate_record_literal(
4040
&mut self,
4141
id: ExprId,
4242
_path: &Option<Path>,
43-
fields: &[StructLitField],
43+
fields: &[RecordLitField],
4444
spread: Option<ExprId>,
4545
db: &impl HirDatabase,
4646
) {
@@ -76,8 +76,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
7676
if let Some(field_list_node) = source_map
7777
.expr_syntax(id)
7878
.map(|ptr| ptr.to_node(source_file.syntax()))
79-
.and_then(StructLit::cast)
80-
.and_then(|lit| lit.named_field_list())
79+
.and_then(RecordLit::cast)
80+
.and_then(|lit| lit.record_field_list())
8181
{
8282
let field_list_ptr = AstPtr::new(&field_list_node);
8383
self.sink.push(MissingFields {

crates/ra_hir/src/source_binder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ impl SourceAnalyzer {
278278
self.infer.as_ref()?.field_resolution(expr_id)
279279
}
280280

281-
pub fn resolve_struct_literal(&self, struct_lit: &ast::StructLit) -> Option<crate::VariantDef> {
282-
let expr_id = self.body_source_map.as_ref()?.node_expr(&struct_lit.clone().into())?;
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(&record_lit.clone().into())?;
283283
self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
284284
}
285285

286-
pub fn resolve_struct_pattern(&self, struct_pat: &ast::StructPat) -> Option<crate::VariantDef> {
287-
let pat_id = self.body_source_map.as_ref()?.node_pat(&struct_pat.clone().into())?;
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(&record_pat.clone().into())?;
288288
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
289289
}
290290

crates/ra_hir/src/ty/infer.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use crate::{
3737
code_model::{ModuleDef::Trait, TypeAlias},
3838
diagnostics::DiagnosticSink,
3939
expr::{
40-
self, Array, BinaryOp, BindingAnnotation, Body, Expr, ExprId, FieldPat, Literal, Pat,
41-
PatId, Statement, UnaryOp,
40+
self, Array, BinaryOp, BindingAnnotation, Body, Expr, ExprId, Literal, Pat, PatId,
41+
RecordFieldPat, Statement, UnaryOp,
4242
},
4343
generics::{GenericParams, HasGenericParams},
4444
name,
@@ -705,10 +705,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
705705
ty
706706
}
707707

708-
fn infer_struct_pat(
708+
fn infer_record_pat(
709709
&mut self,
710710
path: Option<&Path>,
711-
subpats: &[FieldPat],
711+
subpats: &[RecordFieldPat],
712712
expected: &Ty,
713713
default_bm: BindingMode,
714714
id: PatId,
@@ -800,7 +800,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
800800
self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm)
801801
}
802802
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)
804804
}
805805
Pat::Path(path) => {
806806
// FIXME use correct resolver for the surrounding expression
@@ -1103,7 +1103,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
11031103
}
11041104
Ty::simple(TypeCtor::Never)
11051105
}
1106-
Expr::StructLit { path, fields, spread } => {
1106+
Expr::RecordLit { path, fields, spread } => {
11071107
let (ty, def_id) = self.resolve_variant(path.as_ref());
11081108
if let Some(variant) = def_id {
11091109
self.write_variant_resolution(tgt_expr.into(), variant);

crates/ra_ide_api/src/completion.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ mod completion_context;
33
mod presentation;
44

55
mod complete_dot;
6-
mod complete_struct_literal;
7-
mod complete_struct_pattern;
6+
mod complete_record_literal;
7+
mod complete_record_pattern;
88
mod complete_pattern;
99
mod complete_fn_param;
1010
mod complete_keyword;
@@ -65,8 +65,8 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti
6565
complete_path::complete_path(&mut acc, &ctx);
6666
complete_scope::complete_scope(&mut acc, &ctx);
6767
complete_dot::complete_dot(&mut acc, &ctx);
68-
complete_struct_literal::complete_struct_literal(&mut acc, &ctx);
69-
complete_struct_pattern::complete_struct_pattern(&mut acc, &ctx);
68+
complete_record_literal::complete_record_literal(&mut acc, &ctx);
69+
complete_record_pattern::complete_record_pattern(&mut acc, &ctx);
7070
complete_pattern::complete_pattern(&mut acc, &ctx);
7171
complete_postfix::complete_postfix(&mut acc, &ctx);
7272
Some(acc)

crates/ra_ide_api/src/completion/complete_dot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
4545
// FIXME unions
4646
TypeCtor::Tuple { .. } => {
4747
for (i, ty) in a_ty.parameters.iter().enumerate() {
48-
acc.add_pos_field(ctx, i, ty);
48+
acc.add_tuple_field(ctx, i, ty);
4949
}
5050
}
5151
_ => {}

0 commit comments

Comments
 (0)