@@ -584,6 +584,19 @@ impl<T> Trait<T> for X {
584
584
false
585
585
}
586
586
587
+ /// An associated type was expected and a different type was found.
588
+ ///
589
+ /// We perform a few different checks to see what we can suggest:
590
+ ///
591
+ /// - In the current item, look for associated functions that return the expected type and
592
+ /// suggest calling them. (Not a structured suggestion.)
593
+ /// - If any of the item's generic bounds can be constrained, we suggest constraining the
594
+ /// associated type to the found type.
595
+ /// - If the associated type has a default type and was expected inside of a `trait`, we
596
+ /// mention that this is disallowed.
597
+ /// - If all other things fail, and the error is not because of a mismatch between the `trait`
598
+ /// and the `impl`, we provide a generic `help` to constrain the assoc type or call an assoc
599
+ /// fn that returns the type.
587
600
fn expected_projection (
588
601
& self ,
589
602
db : & mut DiagnosticBuilder < ' _ > ,
@@ -600,6 +613,7 @@ impl<T> Trait<T> for X {
600
613
let body_owner = self . hir ( ) . get_if_local ( body_owner_def_id) ;
601
614
let current_method_ident = body_owner. and_then ( |n| n. ident ( ) ) . map ( |i| i. name ) ;
602
615
616
+ // We don't want to suggest calling an assoc fn in a scope where that isn't feasible.
603
617
let callable_scope = match body_owner {
604
618
Some (
605
619
hir:: Node :: Item ( hir:: Item {
@@ -784,6 +798,8 @@ fn foo(&self) -> Self::T { String::new() }
784
798
}
785
799
}
786
800
801
+ /// Given a slice of `hir::GenericBound`s, if any of them corresponds to the `trait_ref`
802
+ /// requirement, provide a strucuted suggestion to constrain it to a given type `ty`.
787
803
fn constrain_generic_bound_associated_type_structured_suggestion (
788
804
& self ,
789
805
db : & mut DiagnosticBuilder < ' _ > ,
@@ -812,6 +828,8 @@ fn foo(&self) -> Self::T { String::new() }
812
828
false
813
829
}
814
830
831
+ /// Given a span corresponding to a bound, provide a structured suggestion to set an
832
+ /// associated type to a given type `ty`.
815
833
fn constrain_associated_type_structured_suggestion (
816
834
& self ,
817
835
db : & mut DiagnosticBuilder < ' _ > ,
0 commit comments