Skip to content

Commit f22e331

Browse files
committed
Back out "Add a test for field default value body as defining usage of TAIT"
This backs out commit 4fe18a6fb5a1181a04c47391f558ebab5b8b0f39.
1 parent ff2656d commit f22e331

File tree

3 files changed

+27
-141
lines changed

3 files changed

+27
-141
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,11 @@ impl HasModule for DefWithBodyId {
13991399
DefWithBodyId::ConstId(it) => it.module(db),
14001400
DefWithBodyId::VariantId(it) => it.module(db),
14011401
DefWithBodyId::InTypeConstId(it) => it.lookup(db).owner.module(db),
1402-
DefWithBodyId::FieldId(it) => it.module(db),
1402+
DefWithBodyId::FieldId(it) => match it.parent {
1403+
VariantId::EnumVariantId(it) => it.module(db),
1404+
VariantId::StructId(it) => it.module(db),
1405+
VariantId::UnionId(it) => it.module(db),
1406+
},
14031407
}
14041408
}
14051409
}

src/tools/rust-analyzer/crates/hir-ty/src/tests.rs

Lines changed: 21 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,19 @@ use std::env;
1616
use std::sync::LazyLock;
1717

1818
use base_db::SourceDatabaseFileInputExt as _;
19-
use either::Either;
2019
use expect_test::Expect;
2120
use hir_def::{
2221
db::DefDatabase,
2322
expr_store::{Body, BodySourceMap},
2423
hir::{ExprId, Pat, PatId},
2524
item_scope::ItemScope,
2625
nameres::DefMap,
27-
src::{HasChildSource, HasSource},
28-
AdtId, AssocItemId, DefWithBodyId, FieldId, HasModule, LocalModuleId, Lookup, ModuleDefId,
29-
SyntheticSyntax,
26+
src::HasSource,
27+
AssocItemId, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleDefId, SyntheticSyntax,
3028
};
3129
use hir_expand::{db::ExpandDatabase, FileRange, InFile};
3230
use itertools::Itertools;
3331
use rustc_hash::FxHashMap;
34-
use span::TextSize;
3532
use stdx::format_to;
3633
use syntax::{
3734
ast::{self, AstNode, HasName},
@@ -135,40 +132,14 @@ fn check_impl(
135132
None => continue,
136133
};
137134
let def_map = module.def_map(&db);
138-
visit_module(&db, &def_map, module.local_id, &mut |it| match it {
139-
ModuleDefId::FunctionId(it) => defs.push(it.into()),
140-
ModuleDefId::EnumVariantId(it) => {
141-
defs.push(it.into());
142-
let variant_id = it.into();
143-
let vd = db.variant_data(variant_id);
144-
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
145-
if fd.has_default {
146-
let field = FieldId { parent: variant_id, local_id, has_default: true };
147-
Some(DefWithBodyId::FieldId(field))
148-
} else {
149-
None
150-
}
151-
}));
152-
}
153-
ModuleDefId::ConstId(it) => defs.push(it.into()),
154-
ModuleDefId::StaticId(it) => defs.push(it.into()),
155-
ModuleDefId::AdtId(it) => {
156-
let variant_id = match it {
157-
AdtId::StructId(it) => it.into(),
158-
AdtId::UnionId(it) => it.into(),
159-
AdtId::EnumId(_) => return,
160-
};
161-
let vd = db.variant_data(variant_id);
162-
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
163-
if fd.has_default {
164-
let field = FieldId { parent: variant_id, local_id, has_default: true };
165-
Some(DefWithBodyId::FieldId(field))
166-
} else {
167-
None
168-
}
169-
}));
170-
}
171-
_ => {}
135+
visit_module(&db, &def_map, module.local_id, &mut |it| {
136+
defs.push(match it {
137+
ModuleDefId::FunctionId(it) => it.into(),
138+
ModuleDefId::EnumVariantId(it) => it.into(),
139+
ModuleDefId::ConstId(it) => it.into(),
140+
ModuleDefId::StaticId(it) => it.into(),
141+
_ => return,
142+
})
172143
});
173144
}
174145
defs.sort_by_key(|def| match def {
@@ -189,20 +160,12 @@ fn check_impl(
189160
loc.source(&db).value.syntax().text_range().start()
190161
}
191162
DefWithBodyId::InTypeConstId(it) => it.source(&db).syntax().text_range().start(),
192-
DefWithBodyId::FieldId(it) => {
193-
let cs = it.parent.child_source(&db);
194-
match cs.value.get(it.local_id) {
195-
Some(Either::Left(it)) => it.syntax().text_range().start(),
196-
Some(Either::Right(it)) => it.syntax().text_range().end(),
197-
None => TextSize::new(u32::MAX),
198-
}
199-
}
163+
DefWithBodyId::FieldId(_) => unreachable!(),
200164
});
201165
let mut unexpected_type_mismatches = String::new();
202166
for def in defs {
203167
let (body, body_source_map) = db.body_with_source_map(def);
204168
let inference_result = db.infer(def);
205-
dbg!(&inference_result);
206169

207170
for (pat, mut ty) in inference_result.type_of_pat.iter() {
208171
if let Pat::Bind { id, .. } = body.pats[pat] {
@@ -426,40 +389,14 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
426389
let def_map = module.def_map(&db);
427390

428391
let mut defs: Vec<DefWithBodyId> = Vec::new();
429-
visit_module(&db, &def_map, module.local_id, &mut |it| match it {
430-
ModuleDefId::FunctionId(it) => defs.push(it.into()),
431-
ModuleDefId::EnumVariantId(it) => {
432-
defs.push(it.into());
433-
let variant_id = it.into();
434-
let vd = db.variant_data(variant_id);
435-
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
436-
if fd.has_default {
437-
let field = FieldId { parent: variant_id, local_id, has_default: true };
438-
Some(DefWithBodyId::FieldId(field))
439-
} else {
440-
None
441-
}
442-
}));
443-
}
444-
ModuleDefId::ConstId(it) => defs.push(it.into()),
445-
ModuleDefId::StaticId(it) => defs.push(it.into()),
446-
ModuleDefId::AdtId(it) => {
447-
let variant_id = match it {
448-
AdtId::StructId(it) => it.into(),
449-
AdtId::UnionId(it) => it.into(),
450-
AdtId::EnumId(_) => return,
451-
};
452-
let vd = db.variant_data(variant_id);
453-
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
454-
if fd.has_default {
455-
let field = FieldId { parent: variant_id, local_id, has_default: true };
456-
Some(DefWithBodyId::FieldId(field))
457-
} else {
458-
None
459-
}
460-
}));
461-
}
462-
_ => {}
392+
visit_module(&db, &def_map, module.local_id, &mut |it| {
393+
defs.push(match it {
394+
ModuleDefId::FunctionId(it) => it.into(),
395+
ModuleDefId::EnumVariantId(it) => it.into(),
396+
ModuleDefId::ConstId(it) => it.into(),
397+
ModuleDefId::StaticId(it) => it.into(),
398+
_ => return,
399+
})
463400
});
464401
defs.sort_by_key(|def| match def {
465402
DefWithBodyId::FunctionId(it) => {
@@ -479,14 +416,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
479416
loc.source(&db).value.syntax().text_range().start()
480417
}
481418
DefWithBodyId::InTypeConstId(it) => it.source(&db).syntax().text_range().start(),
482-
DefWithBodyId::FieldId(it) => {
483-
let cs = it.parent.child_source(&db);
484-
match cs.value.get(it.local_id) {
485-
Some(Either::Left(it)) => it.syntax().text_range().start(),
486-
Some(Either::Right(it)) => it.syntax().text_range().end(),
487-
None => TextSize::new(u32::MAX),
488-
}
489-
}
419+
DefWithBodyId::FieldId(_) => unreachable!(),
490420
});
491421
for def in defs {
492422
let (body, source_map) = db.body_with_source_map(def);
@@ -547,7 +477,7 @@ pub(crate) fn visit_module(
547477
let body = db.body(it.into());
548478
visit_body(db, &body, cb);
549479
}
550-
ModuleDefId::AdtId(AdtId::EnumId(it)) => {
480+
ModuleDefId::AdtId(hir_def::AdtId::EnumId(it)) => {
551481
db.enum_data(it).variants.iter().for_each(|&(it, _)| {
552482
let body = db.body(it.into());
553483
cb(it.into());

src/tools/rust-analyzer/crates/hir-ty/src/tests/type_alias_impl_traits.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -157,53 +157,5 @@ static ALIAS: i32 = {
157157
217..218 '5': i32
158158
205..211: expected impl Trait + ?Sized, got Struct
159159
"#]],
160-
);
161-
}
162-
163-
#[test]
164-
fn defining_type_alias_impl_trait_from_default_fields() {
165-
check_no_mismatches(
166-
r#"
167-
trait Trait {}
168-
169-
struct Struct;
170-
171-
impl Trait for Struct {}
172-
173-
type AliasTy = impl Trait;
174-
175-
struct Foo {
176-
foo: AliasTy = {
177-
let x: AliasTy = Struct;
178-
x
179-
},
180-
}
181-
"#,
182-
);
183-
184-
check_infer_with_mismatches(
185-
r#"
186-
trait Trait {}
187-
188-
struct Struct;
189-
190-
impl Trait for Struct {}
191-
192-
type AliasTy = impl Trait;
193-
194-
struct Foo {
195-
foo: i32 = {
196-
let x: AliasTy = Struct;
197-
5
198-
},
199-
}
200-
"#,
201-
expect![[r#"
202-
114..164 '{ ... }': i32
203-
128..129 'x': impl Trait + ?Sized
204-
141..147 'Struct': Struct
205-
157..158 '5': i32
206-
141..147: expected impl Trait + ?Sized, got Struct
207-
"#]],
208-
);
160+
)
209161
}

0 commit comments

Comments
 (0)