@@ -6,9 +6,10 @@ use derive_where::derive_where;
66use rustc_type_ir:: inherent:: * ;
77use rustc_type_ir:: lang_items:: TraitSolverLangItem ;
88use rustc_type_ir:: {
9- self as ty, Interner , TypeFoldable , TypeVisitableExt as _, TypingMode , Upcast as _, elaborate,
9+ self as ty, Interner , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt as _,
10+ TypingMode , Upcast as _, elaborate,
1011} ;
11- use tracing:: { debug , instrument} ;
12+ use tracing:: instrument;
1213
1314use super :: has_only_region_constraints;
1415use super :: trait_goals:: TraitGoalProvenVia ;
@@ -321,8 +322,7 @@ where
321322 } ;
322323
323324 if normalized_self_ty. is_ty_var ( ) {
324- debug ! ( "self type has been normalized to infer" ) ;
325- return self . forced_ambiguity ( MaybeCause :: Ambiguity ) . into_iter ( ) . collect ( ) ;
325+ return self . try_assemble_bounds_via_registered_opaque ( goal, normalized_self_ty) ;
326326 }
327327
328328 let goal: Goal < I , G > =
@@ -836,6 +836,58 @@ where
836836 }
837837 }
838838
839+ fn try_assemble_bounds_via_registered_opaque < G : GoalKind < D > > (
840+ & mut self ,
841+ goal : Goal < I , G > ,
842+ self_ty : I :: Ty ,
843+ ) -> Vec < Candidate < I > > {
844+ let Some ( alias_ty) = self . find_sup_as_registered_opaque ( self_ty) else {
845+ return self . forced_ambiguity ( MaybeCause :: Ambiguity ) . into_iter ( ) . collect ( ) ;
846+ } ;
847+
848+ let mut candidates = vec ! [ ] ;
849+ for item_bound in
850+ self . cx ( ) . item_self_bounds ( alias_ty. def_id ) . iter_instantiated ( self . cx ( ) , alias_ty. args )
851+ {
852+ // TODO: comment
853+ let assumption =
854+ item_bound. fold_with ( & mut ReplaceOpaque { cx : self . cx ( ) , alias_ty, self_ty } ) ;
855+ candidates. extend ( G :: probe_and_match_goal_against_assumption (
856+ self ,
857+ CandidateSource :: AliasBound ,
858+ goal,
859+ assumption,
860+ |ecx| ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ,
861+ ) ) ;
862+ }
863+
864+ struct ReplaceOpaque < I : Interner > {
865+ cx : I ,
866+ alias_ty : ty:: AliasTy < I > ,
867+ self_ty : I :: Ty ,
868+ }
869+ impl < I : Interner > TypeFolder < I > for ReplaceOpaque < I > {
870+ fn cx ( & self ) -> I {
871+ self . cx
872+ }
873+ fn fold_ty ( & mut self , ty : I :: Ty ) -> I :: Ty {
874+ if let ty:: Alias ( ty:: Opaque , alias_ty) = ty. kind ( ) {
875+ if alias_ty == self . alias_ty {
876+ return self . self_ty ;
877+ }
878+ }
879+ ty. super_fold_with ( self )
880+ }
881+ }
882+
883+ // TODO:
884+ if candidates. is_empty ( ) {
885+ candidates. extend ( self . forced_ambiguity ( MaybeCause :: Ambiguity ) ) ;
886+ }
887+
888+ candidates
889+ }
890+
839891 /// Assemble and merge candidates for goals which are related to an underlying trait
840892 /// goal. Right now, this is normalizes-to and host effect goals.
841893 ///
0 commit comments