@@ -509,13 +509,18 @@ impl<T> Trait<T> for X {
509
509
"consider constraining the associated type `{}` to `{}`" ,
510
510
values. found, values. expected,
511
511
) ;
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 (
513
518
db,
514
519
& msg,
515
520
body_owner_def_id,
516
521
proj_ty,
517
522
values. expected ,
518
- ) {
523
+ ) ) {
519
524
db. help ( & msg) ;
520
525
db. note (
521
526
"for more information, visit \
@@ -699,20 +704,7 @@ impl<T> Trait<T> for X {
699
704
}
700
705
}
701
706
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 ) ;
716
708
717
709
if self . point_at_associated_type ( db, body_owner_def_id, values. found ) {
718
710
return ;
@@ -750,6 +742,30 @@ fn foo(&self) -> Self::T { String::new() }
750
742
}
751
743
}
752
744
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
+
753
769
fn point_at_methods_that_satisfy_associated_type (
754
770
self ,
755
771
db : & mut DiagnosticBuilder < ' _ > ,
0 commit comments