@@ -16,7 +16,7 @@ use rustc_type_ir::fold::TypeFoldable;
16
16
use rustc_type_ir:: inherent:: * ;
17
17
use rustc_type_ir:: relate:: solver_relating:: RelateExt ;
18
18
use rustc_type_ir:: { self as ty, Canonical , CanonicalVarValues , InferCtxtLike , Interner } ;
19
- use tracing:: { instrument, trace} ;
19
+ use tracing:: { debug , instrument, trace} ;
20
20
21
21
use crate :: canonicalizer:: { CanonicalizeMode , Canonicalizer } ;
22
22
use crate :: delegate:: SolverDelegate ;
@@ -165,12 +165,22 @@ where
165
165
// HACK: We bail with overflow if the response would have too many non-region
166
166
// inference variables. This tends to only happen if we encounter a lot of
167
167
// ambiguous alias types which get replaced with fresh inference variables
168
- // during generalization. This prevents a hang in nalgebra.
169
- let num_non_region_vars = canonical. variables . iter ( ) . filter ( |c| !c. is_region ( ) ) . count ( ) ;
170
- if num_non_region_vars > self . cx ( ) . recursion_limit ( ) {
171
- return Ok ( self . make_ambiguous_response_no_constraints ( MaybeCause :: Overflow {
172
- suggest_increasing_limit : true ,
173
- } ) ) ;
168
+ // during generalization. This prevents hangs caused by an exponential blowup,
169
+ // see tests/ui/traits/next-solver/coherence-alias-hang.rs.
170
+ //
171
+ // We don't do so for `NormalizesTo` goals as we erased the expected term and
172
+ // bailing with overflow here would prevent us from detecting a type-mismatch,
173
+ // causing a coherence error in diesel, see #131969. We still bail with verflow
174
+ // when later returning from the parent AliasRelate goal.
175
+ if !self . is_normalizes_to_goal {
176
+ let num_non_region_vars =
177
+ canonical. variables . iter ( ) . filter ( |c| !c. is_region ( ) && c. is_existential ( ) ) . count ( ) ;
178
+ if num_non_region_vars > self . cx ( ) . recursion_limit ( ) {
179
+ debug ! ( ?num_non_region_vars, "too many inference variables -> overflow" ) ;
180
+ return Ok ( self . make_ambiguous_response_no_constraints ( MaybeCause :: Overflow {
181
+ suggest_increasing_limit : true ,
182
+ } ) ) ;
183
+ }
174
184
}
175
185
176
186
Ok ( canonical)
0 commit comments