Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/next_solver/ty.rs')
| -rw-r--r-- | crates/hir-ty/src/next_solver/ty.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index 66a24d3949..1173028a10 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -508,6 +508,11 @@ impl<'db> Ty<'db> { references_non_lt_error(&self) } + /// Whether the type contains a type error (ignoring const and lifetime errors). + pub fn references_only_ty_error(self) -> bool { + references_only_ty_error(&self) + } + pub fn callable_sig(self, interner: DbInterner<'db>) -> Option<Binder<'db, FnSig<'db>>> { match self.kind() { TyKind::FnDef(callable, args) => { @@ -777,6 +782,20 @@ impl<'db> TypeVisitor<DbInterner<'db>> for ReferencesNonLifetimeError { } } +pub fn references_only_ty_error<'db, T: TypeVisitableExt<DbInterner<'db>>>(t: &T) -> bool { + t.references_error() && t.visit_with(&mut ReferencesOnlyTyError).is_break() +} + +struct ReferencesOnlyTyError; + +impl<'db> TypeVisitor<DbInterner<'db>> for ReferencesOnlyTyError { + type Result = ControlFlow<()>; + + fn visit_ty(&mut self, ty: Ty<'db>) -> Self::Result { + if ty.is_ty_error() { ControlFlow::Break(()) } else { ty.super_visit_with(self) } + } +} + impl<'db> std::fmt::Debug for Ty<'db> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.inner().internee.fmt(f) |