@@ -584,6 +584,19 @@ impl<T> Trait<T> for X {
584584 false
585585 }
586586
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.
587600 fn expected_projection (
588601 & self ,
589602 db : & mut DiagnosticBuilder < ' _ > ,
@@ -600,6 +613,7 @@ impl<T> Trait<T> for X {
600613 let body_owner = self . hir ( ) . get_if_local ( body_owner_def_id) ;
601614 let current_method_ident = body_owner. and_then ( |n| n. ident ( ) ) . map ( |i| i. name ) ;
602615
616+ // We don't want to suggest calling an assoc fn in a scope where that isn't feasible.
603617 let callable_scope = match body_owner {
604618 Some (
605619 hir:: Node :: Item ( hir:: Item {
@@ -784,6 +798,8 @@ fn foo(&self) -> Self::T { String::new() }
784798 }
785799 }
786800
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`.
787803 fn constrain_generic_bound_associated_type_structured_suggestion (
788804 & self ,
789805 db : & mut DiagnosticBuilder < ' _ > ,
@@ -812,6 +828,8 @@ fn foo(&self) -> Self::T { String::new() }
812828 false
813829 }
814830
831+ /// Given a span corresponding to a bound, provide a structured suggestion to set an
832+ /// associated type to a given type `ty`.
815833 fn constrain_associated_type_structured_suggestion (
816834 & self ,
817835 db : & mut DiagnosticBuilder < ' _ > ,
0 commit comments