@@ -18,7 +18,7 @@ use rustc_errors::Diagnostic;
18
18
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
19
19
use rustc_hir:: CRATE_HIR_ID ;
20
20
use rustc_infer:: infer:: TyCtxtInferExt ;
21
- use rustc_infer:: traits:: TraitEngine ;
21
+ use rustc_infer:: traits:: { util , TraitEngine } ;
22
22
use rustc_middle:: traits:: specialization_graph:: OverlapMode ;
23
23
use rustc_middle:: ty:: fast_reject:: { self , TreatParams } ;
24
24
use rustc_middle:: ty:: fold:: TypeFoldable ;
@@ -353,6 +353,7 @@ fn negative_impl<'cx, 'tcx>(
353
353
} )
354
354
}
355
355
356
+ #[ instrument( level = "debug" , skip( selcx) ) ]
356
357
fn negative_impl_exists < ' cx , ' tcx > (
357
358
selcx : & SelectionContext < ' cx , ' tcx > ,
358
359
param_env : ty:: ParamEnv < ' tcx > ,
@@ -361,14 +362,18 @@ fn negative_impl_exists<'cx, 'tcx>(
361
362
) -> bool {
362
363
let infcx = & selcx. infcx ( ) . fork ( ) ;
363
364
let tcx = infcx. tcx ;
364
- o. flip_polarity ( tcx)
365
- . map ( |o| {
365
+
366
+ let super_obligations = util:: elaborate_predicates ( tcx, iter:: once ( o. predicate ) ) ;
367
+
368
+ for o in iter:: once ( o. clone ( ) ) . chain ( super_obligations) {
369
+ if let Some ( o) = o. flip_polarity ( tcx) {
366
370
let mut fulfillment_cx = FulfillmentContext :: new ( ) ;
367
371
fulfillment_cx. register_predicate_obligation ( infcx, o) ;
368
372
369
373
let errors = fulfillment_cx. select_all_or_error ( infcx) ;
374
+
370
375
if !errors. is_empty ( ) {
371
- return false ;
376
+ continue ;
372
377
}
373
378
374
379
let mut outlives_env = OutlivesEnvironment :: new ( param_env) ;
@@ -389,13 +394,16 @@ fn negative_impl_exists<'cx, 'tcx>(
389
394
390
395
let errors =
391
396
infcx. resolve_regions ( region_context, & outlives_env, RegionckMode :: default ( ) ) ;
397
+
392
398
if !errors. is_empty ( ) {
393
- return false ;
399
+ continue ;
394
400
}
395
401
396
- true
397
- } )
398
- . unwrap_or ( false )
402
+ return true ;
403
+ }
404
+ }
405
+
406
+ false
399
407
}
400
408
401
409
pub fn trait_ref_is_knowable < ' tcx > (
0 commit comments