diff options
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r-- | crates/hir_ty/src/lower.rs | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 7d22c3df5..4199dc7a6 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -33,9 +33,9 @@ use crate::{ | |||
33 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, | 33 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, |
34 | variant_data, | 34 | variant_data, |
35 | }, | 35 | }, |
36 | AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, | 36 | AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, ImplTraitId, |
37 | GenericPredicate, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, ReturnTypeImplTrait, | 37 | OpaqueTy, PolyFnSig, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, |
38 | ReturnTypeImplTraits, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, | 38 | TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, WhereClause, |
39 | }; | 39 | }; |
40 | 40 | ||
41 | #[derive(Debug)] | 41 | #[derive(Debug)] |
@@ -373,8 +373,7 @@ impl<'a> TyLoweringContext<'a> { | |||
373 | // FIXME report error (ambiguous associated type) | 373 | // FIXME report error (ambiguous associated type) |
374 | TyKind::Unknown.intern(&Interner) | 374 | TyKind::Unknown.intern(&Interner) |
375 | } else { | 375 | } else { |
376 | TyKind::Dyn(Arc::new([GenericPredicate::Implemented(trait_ref)])) | 376 | TyKind::Dyn(Arc::new([WhereClause::Implemented(trait_ref)])).intern(&Interner) |
377 | .intern(&Interner) | ||
378 | }; | 377 | }; |
379 | return (ty, None); | 378 | return (ty, None); |
380 | } | 379 | } |
@@ -667,7 +666,7 @@ impl<'a> TyLoweringContext<'a> { | |||
667 | pub(crate) fn lower_where_predicate( | 666 | pub(crate) fn lower_where_predicate( |
668 | &'a self, | 667 | &'a self, |
669 | where_predicate: &'a WherePredicate, | 668 | where_predicate: &'a WherePredicate, |
670 | ) -> impl Iterator<Item = GenericPredicate> + 'a { | 669 | ) -> impl Iterator<Item = WhereClause> + 'a { |
671 | match where_predicate { | 670 | match where_predicate { |
672 | WherePredicate::ForLifetime { target, bound, .. } | 671 | WherePredicate::ForLifetime { target, bound, .. } |
673 | | WherePredicate::TypeBound { target, bound } => { | 672 | | WherePredicate::TypeBound { target, bound } => { |
@@ -699,17 +698,15 @@ impl<'a> TyLoweringContext<'a> { | |||
699 | &'a self, | 698 | &'a self, |
700 | bound: &'a TypeBound, | 699 | bound: &'a TypeBound, |
701 | self_ty: Ty, | 700 | self_ty: Ty, |
702 | ) -> impl Iterator<Item = GenericPredicate> + 'a { | 701 | ) -> impl Iterator<Item = WhereClause> + 'a { |
703 | let mut bindings = None; | 702 | let mut bindings = None; |
704 | let trait_ref = match bound { | 703 | let trait_ref = match bound { |
705 | TypeBound::Path(path) => { | 704 | TypeBound::Path(path) => { |
706 | bindings = self.lower_trait_ref_from_path(path, Some(self_ty)); | 705 | bindings = self.lower_trait_ref_from_path(path, Some(self_ty)); |
707 | Some( | 706 | Some(bindings.clone().map_or(WhereClause::Error, WhereClause::Implemented)) |
708 | bindings.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented), | ||
709 | ) | ||
710 | } | 707 | } |
711 | TypeBound::Lifetime(_) => None, | 708 | TypeBound::Lifetime(_) => None, |
712 | TypeBound::Error => Some(GenericPredicate::Error), | 709 | TypeBound::Error => Some(WhereClause::Error), |
713 | }; | 710 | }; |
714 | trait_ref.into_iter().chain( | 711 | trait_ref.into_iter().chain( |
715 | bindings | 712 | bindings |
@@ -722,7 +719,7 @@ impl<'a> TyLoweringContext<'a> { | |||
722 | &'a self, | 719 | &'a self, |
723 | bound: &'a TypeBound, | 720 | bound: &'a TypeBound, |
724 | trait_ref: TraitRef, | 721 | trait_ref: TraitRef, |
725 | ) -> impl Iterator<Item = GenericPredicate> + 'a { | 722 | ) -> impl Iterator<Item = WhereClause> + 'a { |
726 | let last_segment = match bound { | 723 | let last_segment = match bound { |
727 | TypeBound::Path(path) => path.segments().last(), | 724 | TypeBound::Path(path) => path.segments().last(), |
728 | TypeBound::Error | TypeBound::Lifetime(_) => None, | 725 | TypeBound::Error | TypeBound::Lifetime(_) => None, |
@@ -738,7 +735,7 @@ impl<'a> TyLoweringContext<'a> { | |||
738 | &binding.name, | 735 | &binding.name, |
739 | ); | 736 | ); |
740 | let (super_trait_ref, associated_ty) = match found { | 737 | let (super_trait_ref, associated_ty) = match found { |
741 | None => return SmallVec::<[GenericPredicate; 1]>::new(), | 738 | None => return SmallVec::<[WhereClause; 1]>::new(), |
742 | Some(t) => t, | 739 | Some(t) => t, |
743 | }; | 740 | }; |
744 | let projection_ty = ProjectionTy { | 741 | let projection_ty = ProjectionTy { |
@@ -752,7 +749,7 @@ impl<'a> TyLoweringContext<'a> { | |||
752 | let ty = self.lower_ty(type_ref); | 749 | let ty = self.lower_ty(type_ref); |
753 | let alias_eq = | 750 | let alias_eq = |
754 | AliasEq { alias: AliasTy::Projection(projection_ty.clone()), ty }; | 751 | AliasEq { alias: AliasTy::Projection(projection_ty.clone()), ty }; |
755 | preds.push(GenericPredicate::AliasEq(alias_eq)); | 752 | preds.push(WhereClause::AliasEq(alias_eq)); |
756 | } | 753 | } |
757 | for bound in &binding.bounds { | 754 | for bound in &binding.bounds { |
758 | preds.extend(self.lower_type_bound( | 755 | preds.extend(self.lower_type_bound( |
@@ -809,7 +806,7 @@ pub fn associated_type_shorthand_candidates<R>( | |||
809 | let mut traits_: Vec<_> = predicates | 806 | let mut traits_: Vec<_> = predicates |
810 | .iter() | 807 | .iter() |
811 | .filter_map(|pred| match &pred.value { | 808 | .filter_map(|pred| match &pred.value { |
812 | GenericPredicate::Implemented(tr) => Some(tr.clone()), | 809 | WhereClause::Implemented(tr) => Some(tr.clone()), |
813 | _ => None, | 810 | _ => None, |
814 | }) | 811 | }) |
815 | .collect(); | 812 | .collect(); |
@@ -881,7 +878,7 @@ pub(crate) fn field_types_query( | |||
881 | pub(crate) fn generic_predicates_for_param_query( | 878 | pub(crate) fn generic_predicates_for_param_query( |
882 | db: &dyn HirDatabase, | 879 | db: &dyn HirDatabase, |
883 | param_id: TypeParamId, | 880 | param_id: TypeParamId, |
884 | ) -> Arc<[Binders<GenericPredicate>]> { | 881 | ) -> Arc<[Binders<WhereClause>]> { |
885 | let resolver = param_id.parent.resolver(db.upcast()); | 882 | let resolver = param_id.parent.resolver(db.upcast()); |
886 | let ctx = | 883 | let ctx = |
887 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 884 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
@@ -907,7 +904,7 @@ pub(crate) fn generic_predicates_for_param_recover( | |||
907 | _db: &dyn HirDatabase, | 904 | _db: &dyn HirDatabase, |
908 | _cycle: &[String], | 905 | _cycle: &[String], |
909 | _param_id: &TypeParamId, | 906 | _param_id: &TypeParamId, |
910 | ) -> Arc<[Binders<GenericPredicate>]> { | 907 | ) -> Arc<[Binders<WhereClause>]> { |
911 | Arc::new([]) | 908 | Arc::new([]) |
912 | } | 909 | } |
913 | 910 | ||
@@ -925,7 +922,7 @@ pub(crate) fn trait_environment_query( | |||
925 | if pred.is_error() { | 922 | if pred.is_error() { |
926 | continue; | 923 | continue; |
927 | } | 924 | } |
928 | if let GenericPredicate::Implemented(tr) = &pred { | 925 | if let WhereClause::Implemented(tr) = &pred { |
929 | traits_in_scope.push((tr.self_type_parameter().clone(), tr.hir_trait_id())); | 926 | traits_in_scope.push((tr.self_type_parameter().clone(), tr.hir_trait_id())); |
930 | } | 927 | } |
931 | let program_clause: chalk_ir::ProgramClause<Interner> = | 928 | let program_clause: chalk_ir::ProgramClause<Interner> = |
@@ -951,7 +948,7 @@ pub(crate) fn trait_environment_query( | |||
951 | cov_mark::hit!(trait_self_implements_self); | 948 | cov_mark::hit!(trait_self_implements_self); |
952 | let substs = Substitution::type_params(db, trait_id); | 949 | let substs = Substitution::type_params(db, trait_id); |
953 | let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; | 950 | let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; |
954 | let pred = GenericPredicate::Implemented(trait_ref); | 951 | let pred = WhereClause::Implemented(trait_ref); |
955 | let program_clause: chalk_ir::ProgramClause<Interner> = | 952 | let program_clause: chalk_ir::ProgramClause<Interner> = |
956 | pred.clone().to_chalk(db).cast(&Interner); | 953 | pred.clone().to_chalk(db).cast(&Interner); |
957 | clauses.push(program_clause.into_from_env_clause(&Interner)); | 954 | clauses.push(program_clause.into_from_env_clause(&Interner)); |
@@ -966,7 +963,7 @@ pub(crate) fn trait_environment_query( | |||
966 | pub(crate) fn generic_predicates_query( | 963 | pub(crate) fn generic_predicates_query( |
967 | db: &dyn HirDatabase, | 964 | db: &dyn HirDatabase, |
968 | def: GenericDefId, | 965 | def: GenericDefId, |
969 | ) -> Arc<[Binders<GenericPredicate>]> { | 966 | ) -> Arc<[Binders<WhereClause>]> { |
970 | let resolver = def.resolver(db.upcast()); | 967 | let resolver = def.resolver(db.upcast()); |
971 | let ctx = | 968 | let ctx = |
972 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 969 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |