@@ -516,8 +516,11 @@ impl<'a> TyLoweringContext<'a> {
516516 TypeNs :: TraitId ( trait_) => {
517517 let ty = match remaining_segments. len ( ) {
518518 1 => {
519- let trait_ref =
520- self . lower_trait_ref_from_resolved_path ( trait_, resolved_segment, None ) ;
519+ let trait_ref = self . lower_trait_ref_from_resolved_path (
520+ trait_,
521+ resolved_segment,
522+ TyKind :: Error . intern ( Interner ) ,
523+ ) ;
521524 let segment = remaining_segments. first ( ) . unwrap ( ) ;
522525 let found = self
523526 . db
@@ -952,11 +955,17 @@ impl<'a> TyLoweringContext<'a> {
952955 Substitution :: from_iter ( Interner , substs)
953956 }
954957
955- fn lower_trait_ref_from_path (
958+ pub ( crate ) fn lower_trait_ref_from_resolved_path (
956959 & self ,
957- path : & Path ,
958- explicit_self_ty : Option < Ty > ,
959- ) -> Option < TraitRef > {
960+ resolved : TraitId ,
961+ segment : PathSegment < ' _ > ,
962+ explicit_self_ty : Ty ,
963+ ) -> TraitRef {
964+ let substs = self . trait_ref_substs_from_path ( segment, resolved, explicit_self_ty) ;
965+ TraitRef { trait_id : to_chalk_trait_id ( resolved) , substitution : substs }
966+ }
967+
968+ fn lower_trait_ref_from_path ( & self , path : & Path , explicit_self_ty : Ty ) -> Option < TraitRef > {
960969 let resolved = match self . resolver . resolve_path_in_type_ns_fully ( self . db . upcast ( ) , path) ? {
961970 // FIXME(trait_alias): We need to handle trait alias here.
962971 TypeNs :: TraitId ( tr) => tr,
@@ -966,31 +975,17 @@ impl<'a> TyLoweringContext<'a> {
966975 Some ( self . lower_trait_ref_from_resolved_path ( resolved, segment, explicit_self_ty) )
967976 }
968977
969- pub ( crate ) fn lower_trait_ref_from_resolved_path (
970- & self ,
971- resolved : TraitId ,
972- segment : PathSegment < ' _ > ,
973- explicit_self_ty : Option < Ty > ,
974- ) -> TraitRef {
975- let substs = self . trait_ref_substs_from_path ( segment, resolved, explicit_self_ty) ;
976- TraitRef { trait_id : to_chalk_trait_id ( resolved) , substitution : substs }
977- }
978-
979- fn lower_trait_ref (
980- & self ,
981- trait_ref : & HirTraitRef ,
982- explicit_self_ty : Option < Ty > ,
983- ) -> Option < TraitRef > {
978+ fn lower_trait_ref ( & self , trait_ref : & HirTraitRef , explicit_self_ty : Ty ) -> Option < TraitRef > {
984979 self . lower_trait_ref_from_path ( & trait_ref. path , explicit_self_ty)
985980 }
986981
987982 fn trait_ref_substs_from_path (
988983 & self ,
989984 segment : PathSegment < ' _ > ,
990985 resolved : TraitId ,
991- explicit_self_ty : Option < Ty > ,
986+ explicit_self_ty : Ty ,
992987 ) -> Substitution {
993- self . substs_from_path_segment ( segment, Some ( resolved. into ( ) ) , false , explicit_self_ty)
988+ self . substs_from_path_segment ( segment, Some ( resolved. into ( ) ) , false , Some ( explicit_self_ty) )
994989 }
995990
996991 pub ( crate ) fn lower_where_predicate < ' b > (
@@ -1041,7 +1036,7 @@ impl<'a> TyLoweringContext<'a> {
10411036 let mut trait_ref = None ;
10421037 let clause = match bound. as_ref ( ) {
10431038 TypeBound :: Path ( path, TraitBoundModifier :: None ) => {
1044- trait_ref = self . lower_trait_ref_from_path ( path, Some ( self_ty) ) ;
1039+ trait_ref = self . lower_trait_ref_from_path ( path, self_ty) ;
10451040 trait_ref. clone ( ) . map ( WhereClause :: Implemented ) . map ( crate :: wrap_empty_binders)
10461041 }
10471042 TypeBound :: Path ( path, TraitBoundModifier :: Maybe ) => {
@@ -1053,7 +1048,7 @@ impl<'a> TyLoweringContext<'a> {
10531048 // `?Sized` has no of them.
10541049 // If we got another trait here ignore the bound completely.
10551050 let trait_id = self
1056- . lower_trait_ref_from_path ( path, Some ( self_ty. clone ( ) ) )
1051+ . lower_trait_ref_from_path ( path, self_ty. clone ( ) )
10571052 . map ( |trait_ref| trait_ref. hir_trait_id ( ) ) ;
10581053 if trait_id == sized_trait {
10591054 self . unsized_types . borrow_mut ( ) . insert ( self_ty) ;
@@ -1062,7 +1057,7 @@ impl<'a> TyLoweringContext<'a> {
10621057 }
10631058 TypeBound :: ForLifetime ( _, path) => {
10641059 // FIXME Don't silently drop the hrtb lifetimes here
1065- trait_ref = self . lower_trait_ref_from_path ( path, Some ( self_ty) ) ;
1060+ trait_ref = self . lower_trait_ref_from_path ( path, self_ty) ;
10661061 trait_ref. clone ( ) . map ( WhereClause :: Implemented ) . map ( crate :: wrap_empty_binders)
10671062 }
10681063 TypeBound :: Lifetime ( l) => {
@@ -2126,7 +2121,7 @@ pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<
21262121 . with_type_param_mode ( ParamLoweringMode :: Variable ) ;
21272122 let ( self_ty, binders) = db. impl_self_ty ( impl_id) . into_value_and_skipped_binders ( ) ;
21282123 let target_trait = impl_data. target_trait . as_ref ( ) ?;
2129- Some ( Binders :: new ( binders, ctx. lower_trait_ref ( target_trait, Some ( self_ty) ) ?) )
2124+ Some ( Binders :: new ( binders, ctx. lower_trait_ref ( target_trait, self_ty) ?) )
21302125}
21312126
21322127pub ( crate ) fn return_type_impl_traits (
0 commit comments