@@ -516,8 +516,11 @@ impl<'a> TyLoweringContext<'a> {
516
516
TypeNs :: TraitId ( trait_) => {
517
517
let ty = match remaining_segments. len ( ) {
518
518
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
+ ) ;
521
524
let segment = remaining_segments. first ( ) . unwrap ( ) ;
522
525
let found = self
523
526
. db
@@ -952,11 +955,17 @@ impl<'a> TyLoweringContext<'a> {
952
955
Substitution :: from_iter ( Interner , substs)
953
956
}
954
957
955
- fn lower_trait_ref_from_path (
958
+ pub ( crate ) fn lower_trait_ref_from_resolved_path (
956
959
& 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 > {
960
969
let resolved = match self . resolver . resolve_path_in_type_ns_fully ( self . db . upcast ( ) , path) ? {
961
970
// FIXME(trait_alias): We need to handle trait alias here.
962
971
TypeNs :: TraitId ( tr) => tr,
@@ -966,31 +975,17 @@ impl<'a> TyLoweringContext<'a> {
966
975
Some ( self . lower_trait_ref_from_resolved_path ( resolved, segment, explicit_self_ty) )
967
976
}
968
977
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 > {
984
979
self . lower_trait_ref_from_path ( & trait_ref. path , explicit_self_ty)
985
980
}
986
981
987
982
fn trait_ref_substs_from_path (
988
983
& self ,
989
984
segment : PathSegment < ' _ > ,
990
985
resolved : TraitId ,
991
- explicit_self_ty : Option < Ty > ,
986
+ explicit_self_ty : Ty ,
992
987
) -> 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) )
994
989
}
995
990
996
991
pub ( crate ) fn lower_where_predicate < ' b > (
@@ -1041,7 +1036,7 @@ impl<'a> TyLoweringContext<'a> {
1041
1036
let mut trait_ref = None ;
1042
1037
let clause = match bound. as_ref ( ) {
1043
1038
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) ;
1045
1040
trait_ref. clone ( ) . map ( WhereClause :: Implemented ) . map ( crate :: wrap_empty_binders)
1046
1041
}
1047
1042
TypeBound :: Path ( path, TraitBoundModifier :: Maybe ) => {
@@ -1053,7 +1048,7 @@ impl<'a> TyLoweringContext<'a> {
1053
1048
// `?Sized` has no of them.
1054
1049
// If we got another trait here ignore the bound completely.
1055
1050
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 ( ) )
1057
1052
. map ( |trait_ref| trait_ref. hir_trait_id ( ) ) ;
1058
1053
if trait_id == sized_trait {
1059
1054
self . unsized_types . borrow_mut ( ) . insert ( self_ty) ;
@@ -1062,7 +1057,7 @@ impl<'a> TyLoweringContext<'a> {
1062
1057
}
1063
1058
TypeBound :: ForLifetime ( _, path) => {
1064
1059
// 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) ;
1066
1061
trait_ref. clone ( ) . map ( WhereClause :: Implemented ) . map ( crate :: wrap_empty_binders)
1067
1062
}
1068
1063
TypeBound :: Lifetime ( l) => {
@@ -2126,7 +2121,7 @@ pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<
2126
2121
. with_type_param_mode ( ParamLoweringMode :: Variable ) ;
2127
2122
let ( self_ty, binders) = db. impl_self_ty ( impl_id) . into_value_and_skipped_binders ( ) ;
2128
2123
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) ?) )
2130
2125
}
2131
2126
2132
2127
pub ( crate ) fn return_type_impl_traits (
0 commit comments