@@ -609,7 +609,6 @@ impl<T> Trait<T> for X {
609
609
"consider constraining the associated type `{}` to `{}`" ,
610
610
values. expected, values. found
611
611
) ;
612
- let mut suggested = false ;
613
612
let body_owner = self . hir ( ) . get_if_local ( body_owner_def_id) ;
614
613
let current_method_ident = body_owner. and_then ( |n| n. ident ( ) ) . map ( |i| i. name ) ;
615
614
@@ -634,7 +633,10 @@ impl<T> Trait<T> for X {
634
633
// type error is a comparison of an `impl` with its `trait` or when the
635
634
// scope is outside of a `Body`.
636
635
} else {
637
- suggested |= self . point_at_methods_that_satisfy_associated_type (
636
+ // If we find a suitable associated function that returns the expected type, we don't
637
+ // want the more general suggestion later in this method about "consider constraining
638
+ // the associated type or calling a method that returns the associated type".
639
+ let point_at_assoc_fn = self . point_at_methods_that_satisfy_associated_type (
638
640
db,
639
641
assoc. container . id ( ) ,
640
642
current_method_ident,
@@ -643,25 +645,32 @@ impl<T> Trait<T> for X {
643
645
) ;
644
646
// Possibly suggest constraining the associated type to conform to the
645
647
// found type.
646
- suggested |=
647
- self . suggest_constraint ( db , & msg , body_owner_def_id , proj_ty , values . found ) ;
648
- }
649
- if !suggested {
650
- suggested = self . point_at_associated_type ( db , body_owner_def_id , values . found ) ;
648
+ if self . suggest_constraint ( db , & msg , body_owner_def_id , proj_ty , values . found )
649
+ || point_at_assoc_fn
650
+ {
651
+ return ;
652
+ }
651
653
}
654
+
652
655
if let ty:: Opaque ( def_id, _) = proj_ty. self_ty ( ) . kind {
653
656
// When the expected `impl Trait` is not defined in the current item, it will come from
654
657
// a return type. This can occur when dealing with `TryStream` (#71035).
655
- suggested |= self . constrain_associated_type_structured_suggestion (
658
+ if self . constrain_associated_type_structured_suggestion (
656
659
db,
657
660
self . def_span ( def_id) ,
658
661
& assoc,
659
662
values. found ,
660
663
& msg,
661
- ) ;
664
+ ) {
665
+ return ;
666
+ }
667
+ }
668
+
669
+ if self . point_at_associated_type ( db, body_owner_def_id, values. found ) {
670
+ return ;
662
671
}
663
672
664
- if !suggested && ! impl_comparison {
673
+ if !impl_comparison {
665
674
// Generic suggestion when we can't be more specific.
666
675
if callable_scope {
667
676
db. help ( & format ! ( "{} or calling a method that returns `{}`" , msg, values. expected) ) ;
0 commit comments