aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/display.rs6
-rw-r--r--crates/hir/src/lib.rs2
-rw-r--r--crates/hir_ty/src/db.rs11
-rw-r--r--crates/hir_ty/src/display.rs12
-rw-r--r--crates/hir_ty/src/infer/expr.rs5
-rw-r--r--crates/hir_ty/src/lib.rs7
-rw-r--r--crates/hir_ty/src/lower.rs18
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs2
-rw-r--r--crates/hir_ty/src/utils.rs2
9 files changed, 28 insertions, 37 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index c96ebb50a..9f6d7be48 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -236,11 +236,7 @@ impl HirDisplay for TypeParam {
236 write!(f, "{}", self.name(f.db))?; 236 write!(f, "{}", self.name(f.db))?;
237 let bounds = f.db.generic_predicates_for_param(self.id); 237 let bounds = f.db.generic_predicates_for_param(self.id);
238 let substs = Substitution::type_params(f.db, self.id.parent); 238 let substs = Substitution::type_params(f.db, self.id.parent);
239 let predicates = bounds 239 let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
240 .iter()
241 .cloned()
242 .map(|b| hir_ty::Binders::new(0, b.subst(&substs)))
243 .collect::<Vec<_>>();
244 if !(predicates.is_empty() || f.omit_verbose_types()) { 240 if !(predicates.is_empty() || f.omit_verbose_types()) {
245 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; 241 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?;
246 } 242 }
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 1844942a6..a325b6691 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1460,7 +1460,7 @@ impl TypeParam {
1460 pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> { 1460 pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
1461 db.generic_predicates_for_param(self.id) 1461 db.generic_predicates_for_param(self.id)
1462 .into_iter() 1462 .into_iter()
1463 .filter_map(|pred| match &pred.value { 1463 .filter_map(|pred| match &pred.skip_binders().skip_binders() {
1464 hir_ty::WhereClause::Implemented(trait_ref) => { 1464 hir_ty::WhereClause::Implemented(trait_ref) => {
1465 Some(Trait::from(trait_ref.hir_trait_id())) 1465 Some(Trait::from(trait_ref.hir_trait_id()))
1466 } 1466 }
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs
index 91a2e0b5b..58e4247c6 100644
--- a/crates/hir_ty/src/db.rs
+++ b/crates/hir_ty/src/db.rs
@@ -12,8 +12,8 @@ use la_arena::ArenaMap;
12use crate::{ 12use crate::{
13 method_resolution::{InherentImpls, TraitImpls}, 13 method_resolution::{InherentImpls, TraitImpls},
14 traits::chalk, 14 traits::chalk,
15 Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig, ReturnTypeImplTraits, 15 Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig,
16 TraitRef, Ty, TyDefId, ValueTyDefId, WhereClause, 16 QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
17}; 17};
18use hir_expand::name::Name; 18use hir_expand::name::Name;
19 19
@@ -57,10 +57,13 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
57 57
58 #[salsa::invoke(crate::lower::generic_predicates_for_param_query)] 58 #[salsa::invoke(crate::lower::generic_predicates_for_param_query)]
59 #[salsa::cycle(crate::lower::generic_predicates_for_param_recover)] 59 #[salsa::cycle(crate::lower::generic_predicates_for_param_recover)]
60 fn generic_predicates_for_param(&self, param_id: TypeParamId) -> Arc<[Binders<WhereClause>]>; 60 fn generic_predicates_for_param(
61 &self,
62 param_id: TypeParamId,
63 ) -> Arc<[Binders<QuantifiedWhereClause>]>;
61 64
62 #[salsa::invoke(crate::lower::generic_predicates_query)] 65 #[salsa::invoke(crate::lower::generic_predicates_query)]
63 fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<WhereClause>]>; 66 fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<QuantifiedWhereClause>]>;
64 67
65 #[salsa::invoke(crate::lower::trait_environment_query)] 68 #[salsa::invoke(crate::lower::trait_environment_query)]
66 fn trait_environment(&self, def: GenericDefId) -> Arc<crate::TraitEnvironment>; 69 fn trait_environment(&self, def: GenericDefId) -> Arc<crate::TraitEnvironment>;
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 372671405..cc6b93d37 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -581,7 +581,7 @@ impl HirDisplay for Ty {
581 .generic_predicates(id.parent) 581 .generic_predicates(id.parent)
582 .into_iter() 582 .into_iter()
583 .map(|pred| pred.clone().subst(&substs)) 583 .map(|pred| pred.clone().subst(&substs))
584 .filter(|wc| match &wc { 584 .filter(|wc| match &wc.skip_binders() {
585 WhereClause::Implemented(tr) => tr.self_type_parameter() == self, 585 WhereClause::Implemented(tr) => tr.self_type_parameter() == self,
586 WhereClause::AliasEq(AliasEq { 586 WhereClause::AliasEq(AliasEq {
587 alias: AliasTy::Projection(proj), 587 alias: AliasTy::Projection(proj),
@@ -590,15 +590,7 @@ impl HirDisplay for Ty {
590 _ => false, 590 _ => false,
591 }) 591 })
592 .collect::<Vec<_>>(); 592 .collect::<Vec<_>>();
593 write_bounds_like_dyn_trait_with_prefix( 593 write_bounds_like_dyn_trait_with_prefix("impl", &bounds, f)?;
594 "impl",
595 &bounds
596 .iter()
597 .cloned()
598 .map(crate::Binders::wrap_empty)
599 .collect::<Vec<_>>(),
600 f,
601 )?;
602 } 594 }
603 } 595 }
604 } 596 }
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 79bbc5dab..17849d552 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -11,6 +11,7 @@ use hir_def::{
11 AssocContainerId, FieldId, Lookup, 11 AssocContainerId, FieldId, Lookup,
12}; 12};
13use hir_expand::name::{name, Name}; 13use hir_expand::name::{name, Name};
14use stdx::always;
14use syntax::ast::RangeOp; 15use syntax::ast::RangeOp;
15 16
16use crate::{ 17use crate::{
@@ -936,7 +937,9 @@ impl<'a> InferenceContext<'a> {
936 let def: CallableDefId = from_chalk(self.db, *fn_def); 937 let def: CallableDefId = from_chalk(self.db, *fn_def);
937 let generic_predicates = self.db.generic_predicates(def.into()); 938 let generic_predicates = self.db.generic_predicates(def.into());
938 for predicate in generic_predicates.iter() { 939 for predicate in generic_predicates.iter() {
939 let predicate = predicate.clone().subst(parameters); 940 let (predicate, binders) =
941 predicate.clone().subst(parameters).into_value_and_skipped_binders();
942 always!(binders == 0); // quantified where clauses not yet handled
940 self.obligations.push(predicate.cast(&Interner)); 943 self.obligations.push(predicate.cast(&Interner));
941 } 944 }
942 // add obligation for trait implementation, if this is a trait method 945 // add obligation for trait implementation, if this is a trait method
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index e4b1f92e4..90b5b17e2 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -518,6 +518,10 @@ impl<T> Binders<T> {
518 pub fn skip_binders(&self) -> &T { 518 pub fn skip_binders(&self) -> &T {
519 &self.value 519 &self.value
520 } 520 }
521
522 pub fn into_value_and_skipped_binders(self) -> (T, usize) {
523 (self.value, self.num_binders)
524 }
521} 525}
522 526
523impl<T: Clone> Binders<&T> { 527impl<T: Clone> Binders<&T> {
@@ -985,7 +989,7 @@ impl Ty {
985 .generic_predicates(id.parent) 989 .generic_predicates(id.parent)
986 .into_iter() 990 .into_iter()
987 .map(|pred| pred.clone().subst(&substs)) 991 .map(|pred| pred.clone().subst(&substs))
988 .filter(|wc| match &wc { 992 .filter(|wc| match &wc.skip_binders() {
989 WhereClause::Implemented(tr) => tr.self_type_parameter() == self, 993 WhereClause::Implemented(tr) => tr.self_type_parameter() == self,
990 WhereClause::AliasEq(AliasEq { 994 WhereClause::AliasEq(AliasEq {
991 alias: AliasTy::Projection(proj), 995 alias: AliasTy::Projection(proj),
@@ -993,7 +997,6 @@ impl Ty {
993 }) => proj.self_type_parameter() == self, 997 }) => proj.self_type_parameter() == self,
994 _ => false, 998 _ => false,
995 }) 999 })
996 .map(Binders::wrap_empty)
997 .collect_vec(); 1000 .collect_vec();
998 1001
999 Some(predicates) 1002 Some(predicates)
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 45591e920..f60cec649 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -825,7 +825,7 @@ pub fn associated_type_shorthand_candidates<R>(
825 let predicates = db.generic_predicates_for_param(param_id); 825 let predicates = db.generic_predicates_for_param(param_id);
826 let mut traits_: Vec<_> = predicates 826 let mut traits_: Vec<_> = predicates
827 .iter() 827 .iter()
828 .filter_map(|pred| match &pred.value { 828 .filter_map(|pred| match &pred.value.value {
829 WhereClause::Implemented(tr) => Some(tr.clone()), 829 WhereClause::Implemented(tr) => Some(tr.clone()),
830 _ => None, 830 _ => None,
831 }) 831 })
@@ -898,10 +898,7 @@ pub(crate) fn field_types_query(
898pub(crate) fn generic_predicates_for_param_query( 898pub(crate) fn generic_predicates_for_param_query(
899 db: &dyn HirDatabase, 899 db: &dyn HirDatabase,
900 param_id: TypeParamId, 900 param_id: TypeParamId,
901) -> Arc<[Binders<WhereClause>]> { 901) -> Arc<[Binders<QuantifiedWhereClause>]> {
902 // FIXME: these binders are for the type parameters of the def. We need to
903 // introduce another level of binders for quantified where clauses (for<'a>
904 // ...)
905 let resolver = param_id.parent.resolver(db.upcast()); 902 let resolver = param_id.parent.resolver(db.upcast());
906 let ctx = 903 let ctx =
907 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); 904 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
@@ -920,7 +917,7 @@ pub(crate) fn generic_predicates_for_param_query(
920 WherePredicate::Lifetime { .. } => false, 917 WherePredicate::Lifetime { .. } => false,
921 }) 918 })
922 .flat_map(|pred| { 919 .flat_map(|pred| {
923 ctx.lower_where_predicate(pred, true).map(|p| Binders::new(generics.len(), p.value)) 920 ctx.lower_where_predicate(pred, true).map(|p| Binders::new(generics.len(), p))
924 }) 921 })
925 .collect() 922 .collect()
926} 923}
@@ -929,7 +926,7 @@ pub(crate) fn generic_predicates_for_param_recover(
929 _db: &dyn HirDatabase, 926 _db: &dyn HirDatabase,
930 _cycle: &[String], 927 _cycle: &[String],
931 _param_id: &TypeParamId, 928 _param_id: &TypeParamId,
932) -> Arc<[Binders<WhereClause>]> { 929) -> Arc<[Binders<QuantifiedWhereClause>]> {
933 Arc::new([]) 930 Arc::new([])
934} 931}
935 932
@@ -984,10 +981,7 @@ pub(crate) fn trait_environment_query(
984pub(crate) fn generic_predicates_query( 981pub(crate) fn generic_predicates_query(
985 db: &dyn HirDatabase, 982 db: &dyn HirDatabase,
986 def: GenericDefId, 983 def: GenericDefId,
987) -> Arc<[Binders<WhereClause>]> { 984) -> Arc<[Binders<QuantifiedWhereClause>]> {
988 // FIXME: these binders are for the type parameters of the def. We need to
989 // introduce another level of binders for quantified where clauses (for<'a>
990 // ...)
991 let resolver = def.resolver(db.upcast()); 985 let resolver = def.resolver(db.upcast());
992 let ctx = 986 let ctx =
993 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); 987 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
@@ -995,7 +989,7 @@ pub(crate) fn generic_predicates_query(
995 resolver 989 resolver
996 .where_predicates_in_scope() 990 .where_predicates_in_scope()
997 .flat_map(|pred| { 991 .flat_map(|pred| {
998 ctx.lower_where_predicate(pred, false).map(|p| Binders::new(generics.len(), p.value)) 992 ctx.lower_where_predicate(pred, false).map(|p| Binders::new(generics.len(), p))
999 }) 993 })
1000 .collect() 994 .collect()
1001} 995}
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 5b9c7e831..7209dd14e 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -537,7 +537,7 @@ pub(super) fn convert_where_clauses(
537 let generic_predicates = db.generic_predicates(def); 537 let generic_predicates = db.generic_predicates(def);
538 let mut result = Vec::with_capacity(generic_predicates.len()); 538 let mut result = Vec::with_capacity(generic_predicates.len());
539 for pred in generic_predicates.iter() { 539 for pred in generic_predicates.iter() {
540 result.push(crate::Binders::wrap_empty(pred.clone().subst(substs)).to_chalk(db)); 540 result.push(pred.clone().subst(substs).to_chalk(db));
541 } 541 }
542 result 542 result
543} 543}
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs
index 1ec1ecd43..19874e42b 100644
--- a/crates/hir_ty/src/utils.rs
+++ b/crates/hir_ty/src/utils.rs
@@ -63,7 +63,7 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec<Tr
63 db.generic_predicates_for_param(trait_self) 63 db.generic_predicates_for_param(trait_self)
64 .iter() 64 .iter()
65 .filter_map(|pred| { 65 .filter_map(|pred| {
66 pred.as_ref().filter_map(|pred| match pred { 66 pred.as_ref().filter_map(|pred| match pred.skip_binders() {
67 WhereClause::Implemented(tr) => Some(tr.clone()), 67 WhereClause::Implemented(tr) => Some(tr.clone()),
68 _ => None, 68 _ => None,
69 }) 69 })