@@ -509,11 +509,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
509509 }
510510}
511511
512+ #[ instrument( skip( tcx) , level = "debug" ) ]
512513fn find_opaque_ty_constraints ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> Ty < ' _ > {
513514 use rustc_hir:: { Expr , ImplItem , Item , TraitItem } ;
514515
515- debug ! ( "find_opaque_ty_constraints({:?})" , def_id) ;
516-
517516 struct ConstraintLocator < ' tcx > {
518517 tcx : TyCtxt < ' tcx > ,
519518 def_id : DefId ,
@@ -522,13 +521,11 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
522521 }
523522
524523 impl ConstraintLocator < ' _ > {
524+ #[ instrument( skip( self ) , level = "debug" ) ]
525525 fn check ( & mut self , def_id : LocalDefId ) {
526526 // Don't try to check items that cannot possibly constrain the type.
527527 if !self . tcx . has_typeck_results ( def_id) {
528- debug ! (
529- "find_opaque_ty_constraints: no constraint for `{:?}` at `{:?}`: no typeck results" ,
530- self . def_id, def_id,
531- ) ;
528+ debug ! ( "no constraint: no typeck results" ) ;
532529 return ;
533530 }
534531 // Calling `mir_borrowck` can lead to cycle errors through
@@ -540,21 +537,19 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
540537 . get_by ( |( key, _) | key. def_id == self . def_id )
541538 . is_none ( )
542539 {
543- debug ! (
544- "find_opaque_ty_constraints: no constraint for `{:?}` at `{:?}`" ,
545- self . def_id, def_id,
546- ) ;
540+ debug ! ( "no constraints in typeck results" ) ;
547541 return ;
548542 }
549543 // Use borrowck to get the type with unerased regions.
550544 let concrete_opaque_types = & self . tcx . mir_borrowck ( def_id) . concrete_opaque_types ;
551- if let Some ( ( opaque_type_key, concrete_type) ) =
552- concrete_opaque_types. iter ( ) . find ( |( key, _) | key. def_id == self . def_id )
553- {
554- debug ! (
555- "find_opaque_ty_constraints: found constraint for `{:?}` at `{:?}`: {:?}" ,
556- self . def_id, def_id, concrete_type,
557- ) ;
545+ debug ! ( ?concrete_opaque_types) ;
546+ for ( opaque_type_key, concrete_type) in concrete_opaque_types {
547+ if opaque_type_key. def_id != self . def_id {
548+ // Ignore constraints for other opaque types.
549+ continue ;
550+ }
551+
552+ debug ! ( ?concrete_type, ?opaque_type_key. substs, "found constraint" ) ;
558553
559554 // FIXME(oli-obk): trace the actual span from inference to improve errors.
560555 let span = self . tcx . def_span ( def_id) ;
@@ -603,7 +598,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
603598
604599 if let Some ( ( prev_span, prev_ty) ) = self . found {
605600 if * concrete_type != prev_ty {
606- debug ! ( "find_opaque_ty_constraints: span={:?}" , span) ;
601+ debug ! ( ? span) ;
607602 // Found different concrete types for the opaque type.
608603 let mut err = self . tcx . sess . struct_span_err (
609604 span,
@@ -619,11 +614,6 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
619614 } else {
620615 self . found = Some ( ( span, concrete_type) ) ;
621616 }
622- } else {
623- debug ! (
624- "find_opaque_ty_constraints: no constraint for `{:?}` at `{:?}`" ,
625- self . def_id, def_id,
626- ) ;
627617 }
628618 }
629619 }
0 commit comments