@@ -262,11 +262,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
262262 // `T` -> `dyn Trait` unsizing
263263 ( _, & ty:: Dynamic ( data, region, ty:: Dyn ) ) => {
264264 // Can only unsize to an object-safe type
265- // FIXME: Can auto traits be *not* object safe?
266265 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) )
270268 {
271269 return Err ( NoSolution ) ;
272270 }
@@ -365,7 +363,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
365363 } )
366364 }
367365
368- fn consider_builtin_dyn_unsize_candidates (
366+ fn consider_builtin_dyn_upcast_candidates (
369367 ecx : & mut EvalCtxt < ' _ , ' tcx > ,
370368 goal : Goal < ' tcx , Self > ,
371369 ) -> Vec < CanonicalResponse < ' tcx > > {
@@ -387,9 +385,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
387385 return vec ! [ ] ;
388386 }
389387
390- let mut responses = vec ! [ ] ;
391388 let mut unsize_dyn_to_principal = |principal : Option < ty:: PolyExistentialTraitRef < ' tcx > > | {
392- let _ = ecx. infcx . probe ( |_| -> Result < ( ) , NoSolution > {
389+ ecx. infcx . probe ( |_| -> Result < _ , NoSolution > {
393390 // Require that all of the trait predicates from A match B, except for
394391 // the auto traits. We do this by constructing a new A type with B's
395392 // auto traits, and equating these types.
@@ -414,16 +411,17 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
414411 goal. with ( tcx, ty:: Binder :: dummy ( ty:: OutlivesPredicate ( a_region, b_region) ) ) ,
415412 ) ;
416413
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+ } )
421416 } ;
422417
418+ let mut responses = vec ! [ ] ;
423419 // If the principal def ids match (or are both none), then we're not doing
424420 // trait upcasting. We're just removing auto traits (or shortening the lifetime).
425421 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+ }
427425 } else if let Some ( a_principal) = a_data. principal ( )
428426 && let Some ( b_principal) = b_data. principal ( )
429427 {
@@ -433,7 +431,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
433431 }
434432 let erased_trait_ref = super_trait_ref
435433 . 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+ }
437437 }
438438 }
439439
0 commit comments