mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 21:04:18 +00:00
Properly handle normalization
Previously normalization was broken, which caused a lot of fake errors. This fix most type mismatches of the new solver, and it also reverts many test regressions. The downside is that now `chalk_ir::TyKind::AssociatedType`/`chalk_ir::TyKind::Alias` cannot be trusted anymore with their roles, namely: `AssociatedType` is always fully normalized and `Alias` only if it can possibly be normalized further. That seems okay as the new solver does not have this distinction at all (due to it being a lazy normalizer), so this will only hold for the migration time. This does mean we have to change some APIs, notably `hir::Type::walk()` and `TyFingerprint`, to treat `Alias` the same as `AssociatedType`. Another small thing this commit does is to isolate processing of user-written types (currently involving replacing error types and normalizing, but in the future validation will also be needed) to separate functions.
This commit is contained in:
parent
0f1adf43df
commit
287a6e9482
15 changed files with 234 additions and 197 deletions
|
|
@ -76,7 +76,7 @@ use hir_expand::{
|
|||
};
|
||||
use hir_ty::{
|
||||
AliasTy, CallableSig, Canonical, CanonicalVarKinds, Cast, ClosureId, GenericArg,
|
||||
GenericArgData, Interner, ParamKind, QuantifiedWhereClause, Scalar, Substitution,
|
||||
GenericArgData, Interner, ParamKind, ProjectionTy, QuantifiedWhereClause, Scalar, Substitution,
|
||||
TraitEnvironment, TraitRefExt, Ty, TyBuilder, TyDefId, TyExt, TyKind, TyLoweringDiagnostic,
|
||||
ValueTyDefId, WhereClause, all_super_traits, autoderef, check_orphan_rules,
|
||||
consteval::{ConstExt, try_const_usize, unknown_const_as_generic},
|
||||
|
|
@ -4973,6 +4973,7 @@ impl<'db> Type<'db> {
|
|||
| TyKind::Tuple(_, substitution)
|
||||
| TyKind::OpaqueType(_, substitution)
|
||||
| TyKind::AssociatedType(_, substitution)
|
||||
| TyKind::Alias(AliasTy::Projection(ProjectionTy { substitution, .. }))
|
||||
| TyKind::FnDef(_, substitution) => {
|
||||
substitution.iter(Interner).filter_map(|x| x.ty(Interner)).any(|ty| go(db, ty))
|
||||
}
|
||||
|
|
@ -5819,7 +5820,11 @@ impl<'db> Type<'db> {
|
|||
cb(type_.derived(ty.clone()));
|
||||
walk_substs(db, type_, substs, cb);
|
||||
}
|
||||
TyKind::AssociatedType(_, substs) => {
|
||||
TyKind::AssociatedType(_, substs)
|
||||
| TyKind::Alias(AliasTy::Projection(hir_ty::ProjectionTy {
|
||||
substitution: substs,
|
||||
..
|
||||
})) => {
|
||||
if ty.associated_type_parent_trait(db).is_some() {
|
||||
cb(type_.derived(ty.clone()));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue