@@ -509,13 +509,18 @@ impl<T> Trait<T> for X {
509509 "consider constraining the associated type `{}` to `{}`" ,
510510 values. found, values. expected,
511511 ) ;
512- if !self . suggest_constraint (
512+ if !( self . suggest_constraining_opaque_associated_type (
513+ db,
514+ & msg,
515+ proj_ty,
516+ values. expected ,
517+ ) || self . suggest_constraint (
513518 db,
514519 & msg,
515520 body_owner_def_id,
516521 proj_ty,
517522 values. expected ,
518- ) {
523+ ) ) {
519524 db. help ( & msg) ;
520525 db. note (
521526 "for more information, visit \
@@ -699,20 +704,7 @@ impl<T> Trait<T> for X {
699704 }
700705 }
701706
702- if let ty:: Opaque ( def_id, _) = * proj_ty. self_ty ( ) . kind ( ) {
703- // When the expected `impl Trait` is not defined in the current item, it will come from
704- // a return type. This can occur when dealing with `TryStream` (#71035).
705- if self . constrain_associated_type_structured_suggestion (
706- db,
707- self . def_span ( def_id) ,
708- & assoc,
709- proj_ty. trait_ref_and_own_substs ( self ) . 1 ,
710- values. found ,
711- & msg,
712- ) {
713- return ;
714- }
715- }
707+ self . suggest_constraining_opaque_associated_type ( db, & msg, proj_ty, values. found ) ;
716708
717709 if self . point_at_associated_type ( db, body_owner_def_id, values. found ) {
718710 return ;
@@ -750,6 +742,30 @@ fn foo(&self) -> Self::T { String::new() }
750742 }
751743 }
752744
745+ /// When the expected `impl Trait` is not defined in the current item, it will come from
746+ /// a return type. This can occur when dealing with `TryStream` (#71035).
747+ fn suggest_constraining_opaque_associated_type (
748+ self ,
749+ db : & mut DiagnosticBuilder < ' _ > ,
750+ msg : & str ,
751+ proj_ty : & ty:: ProjectionTy < ' tcx > ,
752+ ty : Ty < ' tcx > ,
753+ ) -> bool {
754+ let assoc = self . associated_item ( proj_ty. item_def_id ) ;
755+ if let ty:: Opaque ( def_id, _) = * proj_ty. self_ty ( ) . kind ( ) {
756+ self . constrain_associated_type_structured_suggestion (
757+ db,
758+ self . def_span ( def_id) ,
759+ & assoc,
760+ proj_ty. trait_ref_and_own_substs ( self ) . 1 ,
761+ ty,
762+ & msg,
763+ )
764+ } else {
765+ false
766+ }
767+ }
768+
753769 fn point_at_methods_that_satisfy_associated_type (
754770 self ,
755771 db : & mut DiagnosticBuilder < ' _ > ,
0 commit comments