@@ -273,17 +273,17 @@ impl Certainty {
273
273
/// however matter for diagnostics. If `T: Foo` resulted in overflow and `T: Bar`
274
274
/// in ambiguity without changing the inference state, we still want to tell the
275
275
/// user that `T: Baz` results in overflow.
276
- pub fn unify_with ( self , other : Certainty ) -> Certainty {
276
+ pub fn and ( self , other : Certainty ) -> Certainty {
277
277
match ( self , other) {
278
278
( Certainty :: Yes , Certainty :: Yes ) => Certainty :: Yes ,
279
279
( Certainty :: Yes , Certainty :: Maybe ( _) ) => other,
280
280
( Certainty :: Maybe ( _) , Certainty :: Yes ) => self ,
281
- ( Certainty :: Maybe ( a) , Certainty :: Maybe ( b) ) => Certainty :: Maybe ( a. unify_with ( b) ) ,
281
+ ( Certainty :: Maybe ( a) , Certainty :: Maybe ( b) ) => Certainty :: Maybe ( a. and ( b) ) ,
282
282
}
283
283
}
284
284
285
285
pub const fn overflow ( suggest_increasing_limit : bool ) -> Certainty {
286
- Certainty :: Maybe ( MaybeCause :: Overflow { suggest_increasing_limit } )
286
+ Certainty :: Maybe ( MaybeCause :: Overflow { suggest_increasing_limit, keep_constraints : false } )
287
287
}
288
288
}
289
289
@@ -296,19 +296,58 @@ pub enum MaybeCause {
296
296
/// or we hit a case where we just don't bother, e.g. `?x: Trait` goals.
297
297
Ambiguity ,
298
298
/// We gave up due to an overflow, most often by hitting the recursion limit.
299
- Overflow { suggest_increasing_limit : bool } ,
299
+ Overflow { suggest_increasing_limit : bool , keep_constraints : bool } ,
300
300
}
301
301
302
302
impl MaybeCause {
303
- fn unify_with ( self , other : MaybeCause ) -> MaybeCause {
303
+ fn and ( self , other : MaybeCause ) -> MaybeCause {
304
304
match ( self , other) {
305
305
( MaybeCause :: Ambiguity , MaybeCause :: Ambiguity ) => MaybeCause :: Ambiguity ,
306
306
( MaybeCause :: Ambiguity , MaybeCause :: Overflow { .. } ) => other,
307
307
( MaybeCause :: Overflow { .. } , MaybeCause :: Ambiguity ) => self ,
308
308
(
309
- MaybeCause :: Overflow { suggest_increasing_limit : a } ,
310
- MaybeCause :: Overflow { suggest_increasing_limit : b } ,
311
- ) => MaybeCause :: Overflow { suggest_increasing_limit : a || b } ,
309
+ MaybeCause :: Overflow {
310
+ suggest_increasing_limit : limit_a,
311
+ keep_constraints : keep_a,
312
+ } ,
313
+ MaybeCause :: Overflow {
314
+ suggest_increasing_limit : limit_b,
315
+ keep_constraints : keep_b,
316
+ } ,
317
+ ) => MaybeCause :: Overflow {
318
+ suggest_increasing_limit : limit_a && limit_b,
319
+ keep_constraints : keep_a && keep_b,
320
+ } ,
321
+ }
322
+ }
323
+
324
+ pub fn or ( self , other : MaybeCause ) -> MaybeCause {
325
+ match ( self , other) {
326
+ ( MaybeCause :: Ambiguity , MaybeCause :: Ambiguity ) => MaybeCause :: Ambiguity ,
327
+
328
+ // When combining ambiguity + overflow, we can keep constraints.
329
+ (
330
+ MaybeCause :: Ambiguity ,
331
+ MaybeCause :: Overflow { suggest_increasing_limit, keep_constraints : _ } ,
332
+ ) => MaybeCause :: Overflow { suggest_increasing_limit, keep_constraints : true } ,
333
+ (
334
+ MaybeCause :: Overflow { suggest_increasing_limit, keep_constraints : _ } ,
335
+ MaybeCause :: Ambiguity ,
336
+ ) => MaybeCause :: Overflow { suggest_increasing_limit, keep_constraints : true } ,
337
+
338
+ (
339
+ MaybeCause :: Overflow {
340
+ suggest_increasing_limit : limit_a,
341
+ keep_constraints : keep_a,
342
+ } ,
343
+ MaybeCause :: Overflow {
344
+ suggest_increasing_limit : limit_b,
345
+ keep_constraints : keep_b,
346
+ } ,
347
+ ) => MaybeCause :: Overflow {
348
+ suggest_increasing_limit : limit_a || limit_b,
349
+ keep_constraints : keep_a || keep_b,
350
+ } ,
312
351
}
313
352
}
314
353
}
0 commit comments