@@ -15,6 +15,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
1515use rustc_hir:: intravisit:: Visitor ;
1616use rustc_hir:: { self as hir, LangItem , Node } ;
1717use rustc_infer:: infer:: { InferOk , TypeTrace } ;
18+ use rustc_infer:: traits:: ImplSource ;
1819use rustc_infer:: traits:: solve:: Goal ;
1920use rustc_middle:: traits:: SignatureMismatchData ;
2021use rustc_middle:: traits:: select:: OverflowError ;
@@ -48,8 +49,8 @@ use crate::infer::{self, InferCtxt, InferCtxtExt as _};
4849use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
4950use crate :: traits:: {
5051 MismatchedProjectionTypes , NormalizeExt , Obligation , ObligationCause , ObligationCauseCode ,
51- ObligationCtxt , Overflow , PredicateObligation , SelectionError , SignatureMismatch ,
52- TraitDynIncompatible , elaborate,
52+ ObligationCtxt , Overflow , PredicateObligation , SelectionContext , SelectionError ,
53+ SignatureMismatch , TraitDynIncompatible , elaborate, specialization_graph ,
5354} ;
5455
5556impl < ' a , ' tcx > TypeErrCtxt < ' a , ' tcx > {
@@ -1495,32 +1496,33 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14951496 }
14961497 }
14971498
1498- let secondary_span = ( | | {
1499+ let secondary_span = self . probe ( |_ | {
14991500 let ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Projection ( proj) ) =
15001501 predicate. kind ( ) . skip_binder ( )
15011502 else {
15021503 return None ;
15031504 } ;
15041505
1505- let mut associated_items = vec ! [ ] ;
1506- self . tcx . for_each_relevant_impl (
1507- self . tcx . trait_of_item ( proj. projection_term . def_id ) ?,
1508- proj. projection_term . self_ty ( ) ,
1509- |impl_def_id| {
1510- associated_items. extend (
1511- self . tcx . associated_items ( impl_def_id) . in_definition_order ( ) . find (
1512- |assoc| {
1513- assoc. trait_item_def_id == Some ( proj. projection_term . def_id )
1514- } ,
1515- ) ,
1516- ) ;
1517- } ,
1518- ) ;
1506+ let Ok ( Some ( ImplSource :: UserDefined ( impl_data) ) ) = SelectionContext :: new ( self )
1507+ . poly_select ( & obligation. with (
1508+ self . tcx ,
1509+ predicate. kind ( ) . rebind ( proj. projection_term . trait_ref ( self . tcx ) ) ,
1510+ ) )
1511+ else {
1512+ return None ;
1513+ } ;
15191514
1520- let [ associated_item] : & [ ty:: AssocItem ] = & associated_items[ ..] else {
1515+ let Ok ( node) =
1516+ specialization_graph:: assoc_def ( self . tcx , impl_data. impl_def_id , proj. def_id ( ) )
1517+ else {
15211518 return None ;
15221519 } ;
1523- match self . tcx . hir_get_if_local ( associated_item. def_id ) {
1520+
1521+ if !node. is_final ( ) {
1522+ return None ;
1523+ }
1524+
1525+ match self . tcx . hir_get_if_local ( node. item . def_id ) {
15241526 Some (
15251527 hir:: Node :: TraitItem ( hir:: TraitItem {
15261528 kind : hir:: TraitItemKind :: Type ( _, Some ( ty) ) ,
@@ -1543,7 +1545,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15431545 ) ) ,
15441546 _ => None ,
15451547 }
1546- } ) ( ) ;
1548+ } ) ;
15471549
15481550 self . note_type_err (
15491551 & mut diag,
0 commit comments