Skip to content

Commit 0f9cdeb

Browse files
committed
Back out "feat: Implement default-field-values"
This backs out commit 7de0b2e75a541b98f735ee6fcd12d326be38d23f.
1 parent d039b10 commit 0f9cdeb

33 files changed

+31
-647
lines changed

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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
);

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{
1111
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 {

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

Lines changed: 1 addition & 58 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
}
@@ -1379,11 +1332,6 @@ impl HasModule for TypeOwnerId {
13791332
TypeOwnerId::ImplId(it) => it.module(db),
13801333
TypeOwnerId::EnumVariantId(it) => it.module(db),
13811334
TypeOwnerId::InTypeConstId(it) => it.lookup(db).owner.module(db),
1382-
TypeOwnerId::FieldId(it) => match it.parent {
1383-
VariantId::EnumVariantId(it) => it.module(db),
1384-
VariantId::StructId(it) => it.module(db),
1385-
VariantId::UnionId(it) => it.module(db),
1386-
},
13871335
}
13881336
}
13891337
}
@@ -1396,11 +1344,6 @@ impl HasModule for DefWithBodyId {
13961344
DefWithBodyId::ConstId(it) => it.module(db),
13971345
DefWithBodyId::VariantId(it) => it.module(db),
13981346
DefWithBodyId::InTypeConstId(it) => it.lookup(db).owner.module(db),
1399-
DefWithBodyId::FieldId(it) => match it.parent {
1400-
VariantId::EnumVariantId(it) => it.module(db),
1401-
VariantId::StructId(it) => it.module(db),
1402-
VariantId::UnionId(it) => it.module(db),
1403-
},
14041347
}
14051348
}
14061349
}

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

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,6 @@ enum Bar {
211211
#[default]
212212
Bar,
213213
}
214-
#[derive(Default)]
215-
struct Baz {
216-
field1: i32 = 2,
217-
field2: bool = { false },
218-
}
219-
#[derive(Default)]
220-
enum Qux {
221-
#[default]
222-
Foo {
223-
field1: i32,
224-
field2: bool = true,
225-
field3: (),
226-
}
227-
}
228214
"#,
229215
expect![[r#"
230216
#[derive(Default)]
@@ -238,20 +224,6 @@ enum Bar {
238224
#[default]
239225
Bar,
240226
}
241-
#[derive(Default)]
242-
struct Baz {
243-
field1: i32 = 2,
244-
field2: bool = { false },
245-
}
246-
#[derive(Default)]
247-
enum Qux {
248-
#[default]
249-
Foo {
250-
field1: i32,
251-
field2: bool = true,
252-
field3: (),
253-
}
254-
}
255227
256228
impl <> $crate::default::Default for Foo< > where {
257229
fn default() -> Self {
@@ -264,20 +236,6 @@ impl <> $crate::default::Default for Bar< > where {
264236
fn default() -> Self {
265237
Bar::Bar
266238
}
267-
}
268-
impl <> $crate::default::Default for Baz< > where {
269-
fn default() -> Self {
270-
Baz {
271-
..
272-
}
273-
}
274-
}
275-
impl <> $crate::default::Default for Qux< > where {
276-
fn default() -> Self {
277-
Qux::Foo {
278-
field1: $crate::default::Default::default(), field3: $crate::default::Default::default(), ..
279-
}
280-
}
281239
}"#]],
282240
);
283241
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,11 +1227,6 @@ impl HasResolver for TypeOwnerId {
12271227
TypeOwnerId::TypeAliasId(it) => it.resolver(db),
12281228
TypeOwnerId::ImplId(it) => it.resolver(db),
12291229
TypeOwnerId::EnumVariantId(it) => it.resolver(db),
1230-
TypeOwnerId::FieldId(it) => match it.parent {
1231-
VariantId::EnumVariantId(it) => it.resolver(db),
1232-
VariantId::StructId(it) => it.resolver(db),
1233-
VariantId::UnionId(it) => it.resolver(db),
1234-
},
12351230
}
12361231
}
12371232
}
@@ -1244,11 +1239,6 @@ impl HasResolver for DefWithBodyId {
12441239
DefWithBodyId::StaticId(s) => s.resolver(db),
12451240
DefWithBodyId::VariantId(v) => v.resolver(db),
12461241
DefWithBodyId::InTypeConstId(c) => c.lookup(db).owner.resolver(db),
1247-
DefWithBodyId::FieldId(f) => match f.parent {
1248-
VariantId::EnumVariantId(it) => it.resolver(db),
1249-
VariantId::StructId(it) => it.resolver(db),
1250-
VariantId::UnionId(it) => it.resolver(db),
1251-
},
12521242
}
12531243
}
12541244
}

0 commit comments

Comments
 (0)