diff --git a/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs b/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs index d8c1dc8b4e9f3..0fc313e33b323 100644 --- a/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs +++ b/compiler/rustc_next_trait_solver/src/solve/alias_relate.rs @@ -34,7 +34,17 @@ where ) -> QueryResult { let cx = self.cx(); let Goal { param_env, predicate: (lhs, rhs, direction) } = goal; - debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some()); + + // Check that the alias-relate goal is reasonable. Writeback for + // `coroutine_stalled_predicates` can replace alias terms with + // `{type error}` if the alias still contains infer vars, so we also + // accept alias-relate goals where one of the terms is an error. + debug_assert!( + lhs.to_alias_term().is_some() + || rhs.to_alias_term().is_some() + || lhs.is_error() + || rhs.is_error() + ); // Structurally normalize the lhs. let lhs = if let Some(alias) = lhs.to_alias_term() { diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 6924216bd26e6..9277226b718b1 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -126,6 +126,10 @@ pub trait Ty>: matches!(self.kind(), ty::Infer(ty::TyVar(_))) } + fn is_ty_error(self) -> bool { + matches!(self.kind(), ty::Error(_)) + } + fn is_floating_point(self) -> bool { matches!(self.kind(), ty::Float(_) | ty::Infer(ty::FloatVar(_))) } @@ -284,6 +288,10 @@ pub trait Const>: fn is_ct_var(self) -> bool { matches!(self.kind(), ty::ConstKind::Infer(ty::InferConst::Var(_))) } + + fn is_ct_error(self) -> bool { + matches!(self.kind(), ty::ConstKind::Error(_)) + } } pub trait ValueConst>: Copy + Debug + Hash + Eq { @@ -370,6 +378,13 @@ pub trait Term>: } } + fn is_error(self) -> bool { + match self.kind() { + ty::TermKind::Ty(ty) => ty.is_ty_error(), + ty::TermKind::Const(ct) => ct.is_ct_error(), + } + } + fn to_alias_term(self) -> Option> { match self.kind() { ty::TermKind::Ty(ty) => match ty.kind() {