Skip to content

Commit 14cb96e

Browse files
committed
Allign RecordPat with RecordExpr
1 parent 572f1c0 commit 14cb96e

File tree

22 files changed

+78
-85
lines changed

22 files changed

+78
-85
lines changed

crates/ra_assists/src/handlers/reorder_fields.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
5757
fn get_fields_kind(node: &SyntaxNode) -> Vec<SyntaxKind> {
5858
match node.kind() {
5959
RECORD_EXPR => vec![RECORD_EXPR_FIELD],
60-
RECORD_PAT => vec![RECORD_FIELD_PAT, BIND_PAT],
60+
RECORD_PAT => vec![RECORD_PAT_FIELD, BIND_PAT],
6161
_ => vec![],
6262
}
6363
}
@@ -66,7 +66,7 @@ fn get_field_name(node: &SyntaxNode) -> String {
6666
let res = match_ast! {
6767
match node {
6868
ast::RecordExprField(field) => field.field_name().map(|it| it.to_string()),
69-
ast::RecordFieldPat(field) => field.field_name().map(|it| it.to_string()),
69+
ast::RecordPatField(field) => field.field_name().map(|it| it.to_string()),
7070
_ => None,
7171
}
7272
};

crates/ra_hir/src/semantics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
216216
self.imp.resolve_record_field(field)
217217
}
218218

219-
pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> {
219+
pub fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> {
220220
self.imp.resolve_record_field_pat(field)
221221
}
222222

@@ -429,7 +429,7 @@ impl<'db> SemanticsImpl<'db> {
429429
self.analyze(field.syntax()).resolve_record_field(self.db, field)
430430
}
431431

432-
fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> {
432+
fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> {
433433
self.analyze(field.syntax()).resolve_record_field_pat(self.db, field)
434434
}
435435

crates/ra_hir/src/source_analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl SourceAnalyzer {
182182
pub(crate) fn resolve_record_field_pat(
183183
&self,
184184
_db: &dyn HirDatabase,
185-
field: &ast::RecordFieldPat,
185+
field: &ast::RecordPatField,
186186
) -> Option<Field> {
187187
let pat_id = self.pat_id(&field.pat()?)?;
188188
let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?;

crates/ra_hir_def/src/body/lower.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
22
//! representation.
33
4+
use std::{any::type_name, sync::Arc};
5+
46
use either::Either;
57
use hir_expand::{
68
hygiene::Hygiene,
@@ -10,11 +12,12 @@ use hir_expand::{
1012
use ra_arena::Arena;
1113
use ra_syntax::{
1214
ast::{
13-
self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner,
15+
self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner,
1416
SlicePatComponents,
1517
},
1618
AstNode, AstPtr,
1719
};
20+
use rustc_hash::FxHashMap;
1821
use test_utils::mark;
1922

2023
use crate::{
@@ -35,9 +38,6 @@ use crate::{
3538
};
3639

3740
use super::{ExprSource, PatSource};
38-
use ast::AstChildren;
39-
use rustc_hash::FxHashMap;
40-
use std::{any::type_name, sync::Arc};
4141

4242
pub(crate) struct LowerCtx {
4343
hygiene: Hygiene,
@@ -786,29 +786,26 @@ impl ExprCollector<'_> {
786786
ast::Pat::PlaceholderPat(_) => Pat::Wild,
787787
ast::Pat::RecordPat(p) => {
788788
let path = p.path().and_then(|path| self.expander.parse_path(path));
789-
let record_field_pat_list =
790-
p.record_field_pat_list().expect("every struct should have a field list");
791-
let mut fields: Vec<_> = record_field_pat_list
792-
.bind_pats()
793-
.filter_map(|bind_pat| {
794-
let ast_pat =
795-
ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat");
789+
790+
let args: Vec<_> = p
791+
.record_pat_field_list()
792+
.expect("every struct should have a field list")
793+
.fields()
794+
.filter_map(|f| {
795+
let ast_pat = f.pat()?;
796796
let pat = self.collect_pat(ast_pat);
797-
let name = bind_pat.name()?.as_name();
797+
let name = f.field_name()?.as_name();
798798
Some(RecordFieldPat { name, pat })
799799
})
800800
.collect();
801-
let iter = record_field_pat_list.record_field_pats().filter_map(|f| {
802-
let ast_pat = f.pat()?;
803-
let pat = self.collect_pat(ast_pat);
804-
let name = f.field_name()?.as_name();
805-
Some(RecordFieldPat { name, pat })
806-
});
807-
fields.extend(iter);
808801

809-
let ellipsis = record_field_pat_list.dotdot_token().is_some();
802+
let ellipsis = p
803+
.record_pat_field_list()
804+
.expect("every struct should have a field list")
805+
.dotdot_token()
806+
.is_some();
810807

811-
Pat::Record { path, args: fields, ellipsis }
808+
Pat::Record { path, args, ellipsis }
812809
}
813810
ast::Pat::SlicePat(p) => {
814811
let SlicePatComponents { prefix, slice, suffix } = p.components();

crates/ra_hir_ty/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl AstDiagnostic for MissingFields {
9292
#[derive(Debug)]
9393
pub struct MissingPatFields {
9494
pub file: HirFileId,
95-
pub field_list: AstPtr<ast::RecordFieldPatList>,
95+
pub field_list: AstPtr<ast::RecordPatFieldList>,
9696
pub missed_fields: Vec<Name>,
9797
}
9898

crates/ra_hir_ty/src/diagnostics/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
131131
if let Some(expr) = source_ptr.value.as_ref().left() {
132132
let root = source_ptr.file_syntax(db.upcast());
133133
if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) {
134-
if let Some(field_list) = record_pat.record_field_pat_list() {
134+
if let Some(field_list) = record_pat.record_pat_field_list() {
135135
let variant_data = variant_data(db.upcast(), variant_def);
136136
let missed_fields = missed_fields
137137
.into_iter()

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'a> CompletionContext<'a> {
265265
return;
266266
}
267267
// FIXME: remove this (V) duplication and make the check more precise
268-
if name_ref.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() {
268+
if name_ref.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() {
269269
self.record_pat_syntax =
270270
self.sema.find_node_at_offset_with_macros(&original_file, offset);
271271
}
@@ -283,7 +283,7 @@ impl<'a> CompletionContext<'a> {
283283
{
284284
self.is_pat_binding_or_const = false;
285285
}
286-
if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() {
286+
if bind_pat.syntax().parent().and_then(ast::RecordPatFieldList::cast).is_some() {
287287
self.is_pat_binding_or_const = false;
288288
}
289289
if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) {
@@ -300,7 +300,7 @@ impl<'a> CompletionContext<'a> {
300300
return;
301301
}
302302
// FIXME: remove this (^) duplication and make the check more precise
303-
if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() {
303+
if name.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() {
304304
self.record_pat_syntax =
305305
self.sema.find_node_at_offset_with_macros(&original_file, offset);
306306
}

crates/ra_ide/src/extend_selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn try_extend_selection(
3737

3838
let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING];
3939
let list_kinds = [
40-
RECORD_FIELD_PAT_LIST,
40+
RECORD_PAT_FIELD_LIST,
4141
MATCH_ARM_LIST,
4242
RECORD_FIELD_LIST,
4343
TUPLE_FIELD_LIST,

crates/ra_ide/src/folding_ranges.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
8686
USE => Some(FoldKind::Imports),
8787
ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList),
8888
RECORD_FIELD_LIST
89-
| RECORD_FIELD_PAT_LIST
89+
| RECORD_PAT_FIELD_LIST
9090
| RECORD_EXPR_FIELD_LIST
9191
| ITEM_LIST
9292
| EXTERN_ITEM_LIST

crates/ra_ide_db/src/defs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
131131
ast::BindPat(it) => {
132132
let local = sema.to_def(&it)?;
133133

134-
if let Some(record_field_pat) = it.syntax().parent().and_then(ast::RecordFieldPat::cast) {
134+
if let Some(record_field_pat) = it.syntax().parent().and_then(ast::RecordPatField::cast) {
135135
if record_field_pat.name_ref().is_none() {
136136
if let Some(field) = sema.resolve_record_field_pat(&record_field_pat) {
137137
let field = Definition::Field(field);
@@ -247,7 +247,7 @@ pub fn classify_name_ref(
247247
}
248248
}
249249

250-
if let Some(record_field_pat) = ast::RecordFieldPat::cast(parent.clone()) {
250+
if let Some(record_field_pat) = ast::RecordPatField::cast(parent.clone()) {
251251
if let Some(field) = sema.resolve_record_field_pat(&record_field_pat) {
252252
let field = Definition::Field(field);
253253
return Some(NameRefClass::Definition(field));

0 commit comments

Comments
 (0)