Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests.rs')
| -rw-r--r-- | crates/hir-ty/src/tests.rs | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs index 2fa70cd3a8..9e70f69bad 100644 --- a/crates/hir-ty/src/tests.rs +++ b/crates/hir-ty/src/tests.rs @@ -16,8 +16,8 @@ mod traits; use base_db::{Crate, SourceDatabase}; use expect_test::Expect; use hir_def::{ - AssocItemId, DefWithBodyId, GenericDefId, HasModule, Lookup, ModuleDefId, ModuleId, - SyntheticSyntax, + AdtId, AssocItemId, DefWithBodyId, GenericDefId, HasModule, Lookup, ModuleDefId, ModuleId, + SyntheticSyntax, VariantId, expr_store::{Body, BodySourceMap, ExpressionStore, ExpressionStoreSourceMap}, hir::{ExprId, Pat, PatId}, item_scope::ItemScope, @@ -37,6 +37,7 @@ use test_fixture::WithFixture; use crate::{ InferenceDiagnostic, InferenceResult, + db::{AnonConstId, HirDatabase}, display::{DisplayTarget, HirDisplay}, infer::Adjustment, next_solver::Ty, @@ -432,6 +433,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { let mut defs: Vec<(DefWithBodyId, Crate)> = Vec::new(); let mut generic_defs: Vec<(GenericDefId, Crate)> = Vec::new(); + let mut variants: Vec<(VariantId, Crate)> = Vec::new(); visit_module(&db, def_map, module, &mut |it| { let krate = module.krate(&db); match it { @@ -452,6 +454,16 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { } ModuleDefId::AdtId(it) => { generic_defs.push((it.into(), krate)); + match it { + AdtId::StructId(id) => variants.push((id.into(), krate)), + AdtId::UnionId(id) => variants.push((id.into(), krate)), + AdtId::EnumId(id) => variants.extend( + id.enum_variants(&db) + .variants + .iter() + .map(|&(variant, ..)| (variant.into(), krate)), + ), + } } ModuleDefId::TraitId(it) => { generic_defs.push((it.into(), krate)); @@ -511,11 +523,26 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { for (def, krate) in generic_defs { let (store, source_map) = ExpressionStore::with_source_map(&db, def.into()); // Skip if there are no const expressions in the signature - if store.const_expr_origins().is_empty() { + if store.expr_roots().next().is_none() { continue; } - let infer = InferenceResult::of(&db, def); - infer_def(infer, store, source_map, None, krate); + for &anon_const in AnonConstId::all_from_signature(&db, def).into_iter().flatten() { + let infer = InferenceResult::of(&db, anon_const); + infer_def(infer, store, source_map, None, krate); + } + } + variants.dedup(); + for (def, krate) in variants { + let (store, source_map) = ExpressionStore::with_source_map(&db, def.into()); + // Skip if there are no const expressions in the signature + if store.expr_roots().next().is_none() { + continue; + } + let anon_consts = db.field_types_with_diagnostics(def).defined_anon_consts(); + for &anon_const in anon_consts { + let infer = InferenceResult::of(&db, anon_const); + infer_def(infer, store, source_map, None, krate); + } } buf.truncate(buf.trim_end().len()); @@ -572,7 +599,7 @@ pub(crate) fn visit_module( let body = Body::of(db, it.into()); visit_body(db, body, cb); } - ModuleDefId::AdtId(hir_def::AdtId::EnumId(it)) => { + ModuleDefId::AdtId(AdtId::EnumId(it)) => { it.enum_variants(db).variants.iter().for_each(|&(it, _, _)| { let body = Body::of(db, it.into()); cb(it.into()); |