Skip to content

Commit 2386e95

Browse files
authored
Merge pull request rust-lang#19063 from davidbarsky/davidbarsky/backout-struct-default-fields
internal: backout `hir-*` changes from rust-lang#19001
2 parents a355626 + f10b622 commit 2386e95

File tree

31 files changed

+78
-625
lines changed

31 files changed

+78
-625
lines changed

src/tools/rust-analyzer/crates/hir-def/src/data/adt.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ pub struct FieldData {
8585
pub name: Name,
8686
pub type_ref: TypeRefId,
8787
pub visibility: RawVisibility,
88-
pub has_default: bool,
8988
}
9089

9190
fn repr_from_value(
@@ -479,6 +478,5 @@ fn lower_field(
479478
name: field.name.clone(),
480479
type_ref: field.type_ref,
481480
visibility: item_tree[override_visibility.unwrap_or(field.visibility)].clone(),
482-
has_default: field.has_default,
483481
}
484482
}

src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
db::DefDatabase,
2626
hir::{
2727
Array, AsmOperand, Binding, BindingId, Expr, ExprId, ExprOrPatId, Label, LabelId, Pat,
28-
PatId, RecordFieldPat, Spread, Statement,
28+
PatId, RecordFieldPat, Statement,
2929
},
3030
nameres::DefMap,
3131
path::{ModPath, Path},
@@ -362,7 +362,7 @@ impl ExpressionStore {
362362
for field in fields.iter() {
363363
f(field.expr);
364364
}
365-
if let &Spread::Base(expr) = spread {
365+
if let &Some(expr) = spread {
366366
f(expr);
367367
}
368368
}
@@ -490,7 +490,7 @@ impl ExpressionStore {
490490
for field in fields.iter() {
491491
f(field.expr);
492492
}
493-
if let &Spread::Base(expr) = spread {
493+
if let &Some(expr) = spread {
494494
f(expr);
495495
}
496496
}

src/tools/rust-analyzer/crates/hir-def/src/expr_store/body.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ impl Body {
122122
src.map(|it| it.expr())
123123
}
124124
DefWithBodyId::InTypeConstId(c) => c.lookup(db).id.map(|_| c.source(db).expr()),
125-
DefWithBodyId::FieldId(f) => {
126-
f.record_field_source(db).map(|it| it.and_then(|it| it.expr()))
127-
}
128125
}
129126
};
130127
let module = def.module(db);

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::{
4545
},
4646
Array, Binding, BindingAnnotation, BindingId, BindingProblems, CaptureBy, ClosureKind,
4747
Expr, ExprId, Item, Label, LabelId, Literal, LiteralOrConst, MatchArm, Movability,
48-
OffsetOf, Pat, PatId, RecordFieldPat, RecordLitField, Spread, Statement,
48+
OffsetOf, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
4949
},
5050
item_scope::BuiltinShadowMode,
5151
lang_item::LangItem,
@@ -90,7 +90,6 @@ pub(super) fn lower_body(
9090
DefWithBodyId::ConstId(it) => db.attrs(it.into()),
9191
DefWithBodyId::InTypeConstId(_) => Attrs::EMPTY,
9292
DefWithBodyId::VariantId(it) => db.attrs(it.into()),
93-
DefWithBodyId::FieldId(it) => db.attrs(it.into()),
9493
}
9594
.rust_analyzer_tool()
9695
.any(|attr| *attr.path() == tool_path![skip]);
@@ -169,7 +168,6 @@ pub(super) fn lower_body(
169168
Awaitable::No("constant")
170169
}
171170
DefWithBodyId::VariantId(..) => Awaitable::No("enum variant"),
172-
DefWithBodyId::FieldId(..) => Awaitable::No("field"),
173171
}
174172
},
175173
);
@@ -602,13 +600,10 @@ impl ExprCollector<'_> {
602600
Some(RecordLitField { name, expr })
603601
})
604602
.collect();
605-
let spread = nfl.spread().map(|s| self.collect_expr(s)).map_or_else(
606-
|| if nfl.dotdot_token().is_some() { Spread::Yes } else { Spread::No },
607-
Spread::Base,
608-
);
603+
let spread = nfl.spread().map(|s| self.collect_expr(s));
609604
Expr::RecordLit { path, fields, spread }
610605
} else {
611-
Expr::RecordLit { path, fields: Box::default(), spread: Spread::No }
606+
Expr::RecordLit { path, fields: Box::default(), spread: None }
612607
};
613608

614609
self.alloc_expr(record_lit, syntax_ptr)

src/tools/rust-analyzer/crates/hir-def/src/expr_store/pretty.rs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use span::Edition;
88
use crate::{
99
hir::{
1010
Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst, Movability,
11-
Spread, Statement,
11+
Statement,
1212
},
1313
pretty::{print_generic_args, print_path, print_type_ref},
14-
VariantId,
1514
};
1615

1716
use super::*;
@@ -57,32 +56,6 @@ pub(super) fn print_body_hir(
5756
loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition),
5857
)
5958
}
60-
DefWithBodyId::FieldId(it) => {
61-
let parent_name: String = match it.parent {
62-
VariantId::EnumVariantId(it) => {
63-
let loc = it.lookup(db);
64-
let enum_loc = loc.parent.lookup(db);
65-
format!(
66-
"{}::{}",
67-
enum_loc.id.item_tree(db)[enum_loc.id.value]
68-
.name
69-
.display(db.upcast(), edition),
70-
loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition),
71-
)
72-
}
73-
VariantId::StructId(it) => it
74-
.lookup(db)
75-
.id
76-
.resolved(db, |it| it.name.display(db.upcast(), edition).to_string()),
77-
VariantId::UnionId(it) => it
78-
.lookup(db)
79-
.id
80-
.resolved(db, |it| it.name.display(db.upcast(), edition).to_string()),
81-
};
82-
let variant_data = it.parent.variant_data(db);
83-
let field_name = &variant_data.fields()[it.local_id].name;
84-
format!("field {}.{}", parent_name, field_name.display(db.upcast(), edition),)
85-
}
8659
};
8760

8861
let mut p = Printer {
@@ -412,16 +385,10 @@ impl Printer<'_> {
412385
p.print_expr(field.expr);
413386
wln!(p, ",");
414387
}
415-
match spread {
416-
Spread::No => {}
417-
Spread::Yes => {
418-
w!(p, "..");
419-
}
420-
Spread::Base(expr) => {
421-
w!(p, "..");
422-
p.print_expr(*expr);
423-
wln!(p);
424-
}
388+
if let Some(spread) = spread {
389+
w!(p, "..");
390+
p.print_expr(*spread);
391+
wln!(p);
425392
}
426393
});
427394
w!(self, "}}");

src/tools/rust-analyzer/crates/hir-def/src/hir.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub enum Expr {
251251
RecordLit {
252252
path: Option<Box<Path>>,
253253
fields: Box<[RecordLitField]>,
254-
spread: Spread,
254+
spread: Option<ExprId>,
255255
},
256256
Field {
257257
expr: ExprId,
@@ -478,13 +478,6 @@ pub struct RecordLitField {
478478
pub expr: ExprId,
479479
}
480480

481-
#[derive(Debug, Clone, Eq, PartialEq)]
482-
pub enum Spread {
483-
No,
484-
Yes,
485-
Base(ExprId),
486-
}
487-
488481
#[derive(Debug, Clone, Eq, PartialEq)]
489482
pub enum Statement {
490483
Let {

src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,6 @@ pub struct Field {
10071007
pub name: Name,
10081008
pub type_ref: TypeRefId,
10091009
pub visibility: RawVisibilityId,
1010-
pub has_default: bool,
10111010
}
10121011

10131012
#[derive(Debug, Clone, Eq, PartialEq)]

src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,8 @@ impl<'a> Ctx<'a> {
319319
};
320320
let visibility = self.lower_visibility(field);
321321
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
322-
let has_default = field.expr().is_some();
323322

324-
Field { name, type_ref, visibility, has_default }
323+
Field { name, type_ref, visibility }
325324
}
326325

327326
fn lower_tuple_field(
@@ -333,7 +332,7 @@ impl<'a> Ctx<'a> {
333332
let name = Name::new_tuple_field(idx);
334333
let visibility = self.lower_visibility(field);
335334
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
336-
Field { name, type_ref, visibility, has_default: false }
335+
Field { name, type_ref, visibility }
337336
}
338337

339338
fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {

src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ impl Printer<'_> {
135135
self.whitespace();
136136
w!(self, "{{");
137137
self.indented(|this| {
138-
for (idx, Field { name, type_ref, visibility, has_default: _ }) in
139-
fields.iter().enumerate()
140-
{
138+
for (idx, Field { name, type_ref, visibility }) in fields.iter().enumerate() {
141139
this.print_attrs_of(
142140
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
143141
"\n",
@@ -153,9 +151,7 @@ impl Printer<'_> {
153151
FieldsShape::Tuple => {
154152
w!(self, "(");
155153
self.indented(|this| {
156-
for (idx, Field { name, type_ref, visibility, has_default: _ }) in
157-
fields.iter().enumerate()
158-
{
154+
for (idx, Field { name, type_ref, visibility }) in fields.iter().enumerate() {
159155
this.print_attrs_of(
160156
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
161157
"\n",

src/tools/rust-analyzer/crates/hir-def/src/lib.rs

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub mod visibility;
5555

5656
use intern::Interned;
5757
pub use rustc_abi as layout;
58-
use src::HasSource;
5958
use triomphe::Arc;
6059

6160
#[cfg(test)]
@@ -78,7 +77,6 @@ use hir_expand::{
7877
builtin::{BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerExpander},
7978
db::ExpandDatabase,
8079
eager::expand_eager_macro_input,
81-
files::InFileWrapper,
8280
impl_intern_lookup,
8381
name::Name,
8482
proc_macro::{CustomProcMacroExpander, ProcMacroKind},
@@ -521,41 +519,6 @@ pub struct FieldId {
521519
pub local_id: LocalFieldId,
522520
}
523521

524-
impl FieldId {
525-
pub fn record_field_source(
526-
&self,
527-
db: &dyn DefDatabase,
528-
) -> InFileWrapper<HirFileId, Option<ast::RecordField>> {
529-
let field_list = match self.parent {
530-
crate::VariantId::EnumVariantId(it) => {
531-
let s = it.lookup(db);
532-
s.source(db).map(|it| {
533-
it.field_list().and_then(|it| match it {
534-
ast::FieldList::RecordFieldList(it) => Some(it),
535-
_ => None,
536-
})
537-
})
538-
}
539-
crate::VariantId::StructId(it) => {
540-
let s = it.lookup(db);
541-
s.source(db).map(|it| {
542-
it.field_list().and_then(|it| match it {
543-
ast::FieldList::RecordFieldList(it) => Some(it),
544-
_ => None,
545-
})
546-
})
547-
}
548-
crate::VariantId::UnionId(it) => {
549-
let s = it.lookup(db);
550-
s.source(db).map(|it| it.record_field_list())
551-
}
552-
};
553-
field_list.map(|it| {
554-
it.and_then(|it| it.fields().nth(self.local_id.into_raw().into_u32() as usize))
555-
})
556-
}
557-
}
558-
559522
pub type LocalFieldId = Idx<data::adt::FieldData>;
560523

561524
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -723,7 +686,6 @@ pub enum TypeOwnerId {
723686
TypeAliasId(TypeAliasId),
724687
ImplId(ImplId),
725688
EnumVariantId(EnumVariantId),
726-
FieldId(FieldId),
727689
}
728690

729691
impl TypeOwnerId {
@@ -741,11 +703,6 @@ impl TypeOwnerId {
741703
GenericDefId::AdtId(AdtId::EnumId(it.lookup(db).parent))
742704
}
743705
TypeOwnerId::InTypeConstId(_) => return None,
744-
TypeOwnerId::FieldId(it) => GenericDefId::AdtId(match it.parent {
745-
VariantId::EnumVariantId(it) => AdtId::EnumId(it.lookup(db).parent),
746-
VariantId::StructId(it) => it.into(),
747-
VariantId::UnionId(it) => it.into(),
748-
}),
749706
})
750707
}
751708
}
@@ -760,8 +717,7 @@ impl_from!(
760717
TraitAliasId,
761718
TypeAliasId,
762719
ImplId,
763-
EnumVariantId,
764-
FieldId
720+
EnumVariantId
765721
for TypeOwnerId
766722
);
767723

@@ -774,7 +730,6 @@ impl From<DefWithBodyId> for TypeOwnerId {
774730
DefWithBodyId::ConstId(it) => it.into(),
775731
DefWithBodyId::InTypeConstId(it) => it.into(),
776732
DefWithBodyId::VariantId(it) => it.into(),
777-
DefWithBodyId::FieldId(it) => it.into(),
778733
}
779734
}
780735
}
@@ -930,7 +885,6 @@ pub enum DefWithBodyId {
930885
ConstId(ConstId),
931886
InTypeConstId(InTypeConstId),
932887
VariantId(EnumVariantId),
933-
FieldId(FieldId),
934888
}
935889

936890
impl_from!(FunctionId, ConstId, StaticId, InTypeConstId for DefWithBodyId);
@@ -951,7 +905,6 @@ impl DefWithBodyId {
951905
// FIXME: stable rust doesn't allow generics in constants, but we should
952906
// use `TypeOwnerId::as_generic_def_id` when it does.
953907
DefWithBodyId::InTypeConstId(_) => None,
954-
DefWithBodyId::FieldId(_) => None,
955908
}
956909
}
957910
}
@@ -1356,12 +1309,6 @@ impl HasModule for VariantId {
13561309
}
13571310
}
13581311

1359-
impl HasModule for FieldId {
1360-
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
1361-
self.parent.module(db)
1362-
}
1363-
}
1364-
13651312
impl HasModule for MacroId {
13661313
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
13671314
match *self {
@@ -1385,7 +1332,6 @@ impl HasModule for TypeOwnerId {
13851332
TypeOwnerId::ImplId(it) => it.module(db),
13861333
TypeOwnerId::EnumVariantId(it) => it.module(db),
13871334
TypeOwnerId::InTypeConstId(it) => it.lookup(db).owner.module(db),
1388-
TypeOwnerId::FieldId(it) => it.module(db),
13891335
}
13901336
}
13911337
}
@@ -1398,7 +1344,6 @@ impl HasModule for DefWithBodyId {
13981344
DefWithBodyId::ConstId(it) => it.module(db),
13991345
DefWithBodyId::VariantId(it) => it.module(db),
14001346
DefWithBodyId::InTypeConstId(it) => it.lookup(db).owner.module(db),
1401-
DefWithBodyId::FieldId(it) => it.module(db),
14021347
}
14031348
}
14041349
}

0 commit comments

Comments
 (0)