aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r--crates/hir_ty/src/lower.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 5fa83567b..d84ec9b7a 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -8,7 +8,7 @@
8use std::{iter, sync::Arc}; 8use std::{iter, sync::Arc};
9 9
10use base_db::CrateId; 10use base_db::CrateId;
11use chalk_ir::Mutability; 11use chalk_ir::{cast::Cast, Mutability};
12use hir_def::{ 12use hir_def::{
13 adt::StructKind, 13 adt::StructKind,
14 builtin_type::BuiltinType, 14 builtin_type::BuiltinType,
@@ -27,6 +27,7 @@ use stdx::impl_from;
27 27
28use crate::{ 28use crate::{
29 db::HirDatabase, 29 db::HirDatabase,
30 traits::chalk::{Interner, ToChalk},
30 utils::{ 31 utils::{
31 all_super_trait_refs, associated_type_by_name_including_super_traits, generics, 32 all_super_trait_refs, associated_type_by_name_including_super_traits, generics,
32 make_mut_slice, variant_data, 33 make_mut_slice, variant_data,
@@ -914,10 +915,21 @@ impl TraitEnvironment {
914 pub fn lower(db: &dyn HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> { 915 pub fn lower(db: &dyn HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> {
915 let ctx = TyLoweringContext::new(db, &resolver) 916 let ctx = TyLoweringContext::new(db, &resolver)
916 .with_type_param_mode(TypeParamLoweringMode::Placeholder); 917 .with_type_param_mode(TypeParamLoweringMode::Placeholder);
917 let mut predicates = resolver 918 let mut traits_in_scope = Vec::new();
918 .where_predicates_in_scope() 919 let mut clauses = Vec::new();
919 .flat_map(|pred| GenericPredicate::from_where_predicate(&ctx, pred)) 920 for pred in resolver.where_predicates_in_scope() {
920 .collect::<Vec<_>>(); 921 for pred in GenericPredicate::from_where_predicate(&ctx, pred) {
922 if pred.is_error() {
923 continue;
924 }
925 if let GenericPredicate::Implemented(tr) = &pred {
926 traits_in_scope.push((tr.self_ty().clone(), tr.trait_));
927 }
928 let program_clause: chalk_ir::ProgramClause<Interner> =
929 pred.clone().to_chalk(db).cast(&Interner);
930 clauses.push(program_clause.into_from_env_clause(&Interner));
931 }
932 }
921 933
922 if let Some(def) = resolver.generic_def() { 934 if let Some(def) = resolver.generic_def() {
923 let container: Option<AssocContainerId> = match def { 935 let container: Option<AssocContainerId> = match def {
@@ -938,12 +950,15 @@ impl TraitEnvironment {
938 let substs = Substs::type_params(db, trait_id); 950 let substs = Substs::type_params(db, trait_id);
939 let trait_ref = TraitRef { trait_: trait_id, substs }; 951 let trait_ref = TraitRef { trait_: trait_id, substs };
940 let pred = GenericPredicate::Implemented(trait_ref); 952 let pred = GenericPredicate::Implemented(trait_ref);
941 953 let program_clause: chalk_ir::ProgramClause<Interner> =
942 predicates.push(pred); 954 pred.clone().to_chalk(db).cast(&Interner);
955 clauses.push(program_clause.into_from_env_clause(&Interner));
943 } 956 }
944 } 957 }
945 958
946 Arc::new(TraitEnvironment { predicates }) 959 let env = chalk_ir::Environment::new(&Interner).add_clauses(&Interner, clauses);
960
961 Arc::new(TraitEnvironment { traits_from_clauses: traits_in_scope, env })
947 } 962 }
948} 963}
949 964