@@ -262,11 +262,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
262
262
// `T` -> `dyn Trait` unsizing
263
263
( _, & ty:: Dynamic ( data, region, ty:: Dyn ) ) => {
264
264
// Can only unsize to an object-safe type
265
- // FIXME: Can auto traits be *not* object safe?
266
265
if data
267
- . auto_traits ( )
268
- . chain ( data. principal_def_id ( ) )
269
- . any ( |def_id| !tcx. is_object_safe ( def_id) )
266
+ . principal_def_id ( )
267
+ . map_or ( false , |def_id| !tcx. check_is_object_safe ( def_id) )
270
268
{
271
269
return Err ( NoSolution ) ;
272
270
}
@@ -365,7 +363,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
365
363
} )
366
364
}
367
365
368
- fn consider_builtin_dyn_unsize_candidates (
366
+ fn consider_builtin_dyn_upcast_candidates (
369
367
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
370
368
goal : Goal < ' tcx , Self > ,
371
369
) -> Vec < CanonicalResponse < ' tcx > > {
@@ -387,9 +385,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
387
385
return vec ! [ ] ;
388
386
}
389
387
390
- let mut responses = vec ! [ ] ;
391
388
let mut unsize_dyn_to_principal = |principal : Option < ty:: PolyExistentialTraitRef < ' tcx > > | {
392
- let _ = ecx. infcx . probe ( |_| -> Result < ( ) , NoSolution > {
389
+ ecx. infcx . probe ( |_| -> Result < _ , NoSolution > {
393
390
// Require that all of the trait predicates from A match B, except for
394
391
// the auto traits. We do this by constructing a new A type with B's
395
392
// auto traits, and equating these types.
@@ -414,16 +411,17 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
414
411
goal. with ( tcx, ty:: Binder :: dummy ( ty:: OutlivesPredicate ( a_region, b_region) ) ) ,
415
412
) ;
416
413
417
- responses. push ( ecx. evaluate_all_and_make_canonical_response ( nested_obligations) ?) ;
418
-
419
- Ok ( ( ) )
420
- } ) ;
414
+ ecx. evaluate_all_and_make_canonical_response ( nested_obligations)
415
+ } )
421
416
} ;
422
417
418
+ let mut responses = vec ! [ ] ;
423
419
// If the principal def ids match (or are both none), then we're not doing
424
420
// trait upcasting. We're just removing auto traits (or shortening the lifetime).
425
421
if a_data. principal_def_id ( ) == b_data. principal_def_id ( ) {
426
- unsize_dyn_to_principal ( a_data. principal ( ) ) ;
422
+ if let Ok ( response) = unsize_dyn_to_principal ( a_data. principal ( ) ) {
423
+ responses. push ( response) ;
424
+ }
427
425
} else if let Some ( a_principal) = a_data. principal ( )
428
426
&& let Some ( b_principal) = b_data. principal ( )
429
427
{
@@ -433,7 +431,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
433
431
}
434
432
let erased_trait_ref = super_trait_ref
435
433
. map_bound ( |trait_ref| ty:: ExistentialTraitRef :: erase_self_ty ( tcx, trait_ref) ) ;
436
- unsize_dyn_to_principal ( Some ( erased_trait_ref) ) ;
434
+ if let Ok ( response) = unsize_dyn_to_principal ( Some ( erased_trait_ref) ) {
435
+ responses. push ( response) ;
436
+ }
437
437
}
438
438
}
439
439
0 commit comments