aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-20 09:47:46 +0000
committerGitHub <[email protected]>2021-03-20 09:47:46 +0000
commit3901c3b566a6834c64e029bd6f4fdaaf8b26f809 (patch)
treefedc1b02375558b9bd027a318c4bc131784d58c6
parent8b16af590dd3d241bec07f69f4d4dadae9a4b523 (diff)
parent7a5fb37cf12f4e25ce1ba7e464dd257408444bfb (diff)
Merge #8115
8115: Rename GenericPredicate -> WhereClause r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
-rw-r--r--crates/hir/src/lib.rs12
-rw-r--r--crates/hir_ty/src/db.rs11
-rw-r--r--crates/hir_ty/src/display.rs29
-rw-r--r--crates/hir_ty/src/infer/unify.rs17
-rw-r--r--crates/hir_ty/src/lib.rs38
-rw-r--r--crates/hir_ty/src/lower.rs37
-rw-r--r--crates/hir_ty/src/traits.rs12
-rw-r--r--crates/hir_ty/src/traits/chalk.rs8
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs26
-rw-r--r--crates/hir_ty/src/utils.rs4
10 files changed, 89 insertions, 105 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 300087f1f..268a2b901 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -57,8 +57,8 @@ use hir_ty::{
57 to_assoc_type_id, 57 to_assoc_type_id,
58 traits::{FnTrait, Solution, SolutionVariables}, 58 traits::{FnTrait, Solution, SolutionVariables},
59 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, 59 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex,
60 GenericPredicate, InEnvironment, Interner, Obligation, ProjectionTy, Scalar, Substitution, Ty, 60 InEnvironment, Interner, Obligation, ProjectionTy, Scalar, Substitution, Ty, TyDefId, TyKind,
61 TyDefId, TyKind, TyVariableKind, 61 TyVariableKind, WhereClause,
62}; 62};
63use itertools::Itertools; 63use itertools::Itertools;
64use rustc_hash::FxHashSet; 64use rustc_hash::FxHashSet;
@@ -1461,7 +1461,7 @@ impl TypeParam {
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.value {
1464 hir_ty::GenericPredicate::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 }
1467 _ => None, 1467 _ => None,
@@ -2022,7 +2022,7 @@ impl Type {
2022 self.ty.value.impl_trait_bounds(db).map(|it| { 2022 self.ty.value.impl_trait_bounds(db).map(|it| {
2023 it.into_iter() 2023 it.into_iter()
2024 .filter_map(|pred| match pred { 2024 .filter_map(|pred| match pred {
2025 hir_ty::GenericPredicate::Implemented(trait_ref) => { 2025 hir_ty::WhereClause::Implemented(trait_ref) => {
2026 Some(Trait::from(trait_ref.hir_trait_id())) 2026 Some(Trait::from(trait_ref.hir_trait_id()))
2027 } 2027 }
2028 _ => None, 2028 _ => None,
@@ -2060,12 +2060,12 @@ impl Type {
2060 fn walk_bounds( 2060 fn walk_bounds(
2061 db: &dyn HirDatabase, 2061 db: &dyn HirDatabase,
2062 type_: &Type, 2062 type_: &Type,
2063 bounds: &[GenericPredicate], 2063 bounds: &[WhereClause],
2064 cb: &mut impl FnMut(Type), 2064 cb: &mut impl FnMut(Type),
2065 ) { 2065 ) {
2066 for pred in bounds { 2066 for pred in bounds {
2067 match pred { 2067 match pred {
2068 GenericPredicate::Implemented(trait_ref) => { 2068 WhereClause::Implemented(trait_ref) => {
2069 cb(type_.clone()); 2069 cb(type_.clone());
2070 walk_substs(db, type_, &trait_ref.substitution, cb); 2070 walk_substs(db, type_, &trait_ref.substitution, cb);
2071 } 2071 }
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs
index 74a048672..300da0f38 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, GenericPredicate, ImplTraitId, InferenceResult, PolyFnSig, 15 Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig, ReturnTypeImplTraits,
16 ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, 16 TraitRef, Ty, TyDefId, ValueTyDefId, WhereClause,
17}; 17};
18use hir_expand::name::Name; 18use hir_expand::name::Name;
19 19
@@ -57,13 +57,10 @@ 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( 60 fn generic_predicates_for_param(&self, param_id: TypeParamId) -> Arc<[Binders<WhereClause>]>;
61 &self,
62 param_id: TypeParamId,
63 ) -> Arc<[Binders<GenericPredicate>]>;
64 61
65 #[salsa::invoke(crate::lower::generic_predicates_query)] 62 #[salsa::invoke(crate::lower::generic_predicates_query)]
66 fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<GenericPredicate>]>; 63 fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<WhereClause>]>;
67 64
68 #[salsa::invoke(crate::lower::trait_environment_query)] 65 #[salsa::invoke(crate::lower::trait_environment_query)]
69 fn trait_environment(&self, def: GenericDefId) -> Arc<crate::TraitEnvironment>; 66 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 59a1bd9b0..2721b8312 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -19,8 +19,8 @@ use hir_expand::name::Name;
19use crate::{ 19use crate::{
20 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, 20 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive,
21 to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, 21 to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy,
22 CallableDefId, CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, 22 CallableDefId, CallableSig, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy,
23 OpaqueTy, ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, 23 ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, WhereClause,
24}; 24};
25 25
26pub struct HirFormatter<'a> { 26pub struct HirFormatter<'a> {
@@ -353,7 +353,7 @@ impl HirDisplay for Ty {
353 _ => Cow::Borrowed(&[][..]), 353 _ => Cow::Borrowed(&[][..]),
354 }; 354 };
355 355
356 if let [GenericPredicate::Implemented(trait_ref), _] = predicates.as_ref() { 356 if let [WhereClause::Implemented(trait_ref), _] = predicates.as_ref() {
357 let trait_ = trait_ref.hir_trait_id(); 357 let trait_ = trait_ref.hir_trait_id();
358 if fn_traits(f.db.upcast(), trait_).any(|it| it == trait_) { 358 if fn_traits(f.db.upcast(), trait_).any(|it| it == trait_) {
359 return write!(f, "{}", ty_display); 359 return write!(f, "{}", ty_display);
@@ -652,7 +652,7 @@ fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = Trai
652 652
653pub fn write_bounds_like_dyn_trait_with_prefix( 653pub fn write_bounds_like_dyn_trait_with_prefix(
654 prefix: &str, 654 prefix: &str,
655 predicates: &[GenericPredicate], 655 predicates: &[WhereClause],
656 f: &mut HirFormatter, 656 f: &mut HirFormatter,
657) -> Result<(), HirDisplayError> { 657) -> Result<(), HirDisplayError> {
658 write!(f, "{}", prefix)?; 658 write!(f, "{}", prefix)?;
@@ -665,7 +665,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix(
665} 665}
666 666
667fn write_bounds_like_dyn_trait( 667fn write_bounds_like_dyn_trait(
668 predicates: &[GenericPredicate], 668 predicates: &[WhereClause],
669 f: &mut HirFormatter, 669 f: &mut HirFormatter,
670) -> Result<(), HirDisplayError> { 670) -> Result<(), HirDisplayError> {
671 // Note: This code is written to produce nice results (i.e. 671 // Note: This code is written to produce nice results (i.e.
@@ -679,7 +679,7 @@ fn write_bounds_like_dyn_trait(
679 let mut is_fn_trait = false; 679 let mut is_fn_trait = false;
680 for p in predicates.iter() { 680 for p in predicates.iter() {
681 match p { 681 match p {
682 GenericPredicate::Implemented(trait_ref) => { 682 WhereClause::Implemented(trait_ref) => {
683 let trait_ = trait_ref.hir_trait_id(); 683 let trait_ = trait_ref.hir_trait_id();
684 if !is_fn_trait { 684 if !is_fn_trait {
685 is_fn_trait = fn_traits(f.db.upcast(), trait_).any(|it| it == trait_); 685 is_fn_trait = fn_traits(f.db.upcast(), trait_).any(|it| it == trait_);
@@ -710,12 +710,12 @@ fn write_bounds_like_dyn_trait(
710 } 710 }
711 } 711 }
712 } 712 }
713 GenericPredicate::AliasEq(alias_eq) if is_fn_trait => { 713 WhereClause::AliasEq(alias_eq) if is_fn_trait => {
714 is_fn_trait = false; 714 is_fn_trait = false;
715 write!(f, " -> ")?; 715 write!(f, " -> ")?;
716 alias_eq.ty.hir_fmt(f)?; 716 alias_eq.ty.hir_fmt(f)?;
717 } 717 }
718 GenericPredicate::AliasEq(AliasEq { ty, alias }) => { 718 WhereClause::AliasEq(AliasEq { ty, alias }) => {
719 // in types in actual Rust, these will always come 719 // in types in actual Rust, these will always come
720 // after the corresponding Implemented predicate 720 // after the corresponding Implemented predicate
721 if angle_open { 721 if angle_open {
@@ -731,7 +731,7 @@ fn write_bounds_like_dyn_trait(
731 } 731 }
732 ty.hir_fmt(f)?; 732 ty.hir_fmt(f)?;
733 } 733 }
734 GenericPredicate::Error => { 734 WhereClause::Error => {
735 if angle_open { 735 if angle_open {
736 // impl Trait<X, {error}> 736 // impl Trait<X, {error}>
737 write!(f, ", ")?; 737 write!(f, ", ")?;
@@ -778,18 +778,15 @@ impl HirDisplay for TraitRef {
778 } 778 }
779} 779}
780 780
781impl HirDisplay for GenericPredicate { 781impl HirDisplay for WhereClause {
782 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 782 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
783 if f.should_truncate() { 783 if f.should_truncate() {
784 return write!(f, "{}", TYPE_HINT_TRUNCATION); 784 return write!(f, "{}", TYPE_HINT_TRUNCATION);
785 } 785 }
786 786
787 match self { 787 match self {
788 GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, 788 WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?,
789 GenericPredicate::AliasEq(AliasEq { 789 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
790 alias: AliasTy::Projection(projection_ty),
791 ty,
792 }) => {
793 write!(f, "<")?; 790 write!(f, "<")?;
794 projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; 791 projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?;
795 write!( 792 write!(
@@ -799,7 +796,7 @@ impl HirDisplay for GenericPredicate {
799 )?; 796 )?;
800 ty.hir_fmt(f)?; 797 ty.hir_fmt(f)?;
801 } 798 }
802 GenericPredicate::AliasEq(_) | GenericPredicate::Error => write!(f, "{{error}}")?, 799 WhereClause::AliasEq(_) | WhereClause::Error => write!(f, "{{error}}")?,
803 } 800 }
804 Ok(()) 801 Ok(())
805 } 802 }
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 4738ec08a..5b7b423fa 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -7,8 +7,8 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
7 7
8use super::{InferenceContext, Obligation}; 8use super::{InferenceContext, Obligation};
9use crate::{ 9use crate::{
10 AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, GenericPredicate, 10 AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, InEnvironment, InferenceVar,
11 InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, 11 Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, WhereClause,
12}; 12};
13 13
14impl<'a> InferenceContext<'a> { 14impl<'a> InferenceContext<'a> {
@@ -382,21 +382,16 @@ impl InferenceTable {
382 } 382 }
383 } 383 }
384 384
385 fn unify_preds( 385 fn unify_preds(&mut self, pred1: &WhereClause, pred2: &WhereClause, depth: usize) -> bool {
386 &mut self,
387 pred1: &GenericPredicate,
388 pred2: &GenericPredicate,
389 depth: usize,
390 ) -> bool {
391 match (pred1, pred2) { 386 match (pred1, pred2) {
392 (GenericPredicate::Implemented(tr1), GenericPredicate::Implemented(tr2)) 387 (WhereClause::Implemented(tr1), WhereClause::Implemented(tr2))
393 if tr1.trait_id == tr2.trait_id => 388 if tr1.trait_id == tr2.trait_id =>
394 { 389 {
395 self.unify_substs(&tr1.substitution, &tr2.substitution, depth + 1) 390 self.unify_substs(&tr1.substitution, &tr2.substitution, depth + 1)
396 } 391 }
397 ( 392 (
398 GenericPredicate::AliasEq(AliasEq { alias: alias1, ty: ty1 }), 393 WhereClause::AliasEq(AliasEq { alias: alias1, ty: ty1 }),
399 GenericPredicate::AliasEq(AliasEq { alias: alias2, ty: ty2 }), 394 WhereClause::AliasEq(AliasEq { alias: alias2, ty: ty2 }),
400 ) => { 395 ) => {
401 let (substitution1, substitution2) = match (alias1, alias2) { 396 let (substitution1, substitution2) = match (alias1, alias2) {
402 (AliasTy::Projection(projection_ty1), AliasTy::Projection(projection_ty2)) 397 (AliasTy::Projection(projection_ty1), AliasTy::Projection(projection_ty2))
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 2afcb5413..5c4d5a7d7 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -276,7 +276,7 @@ pub enum TyKind {
276 /// represents the `Self` type inside the bounds. This is currently 276 /// represents the `Self` type inside the bounds. This is currently
277 /// implicit; Chalk has the `Binders` struct to make it explicit, but it 277 /// implicit; Chalk has the `Binders` struct to make it explicit, but it
278 /// didn't seem worth the overhead yet. 278 /// didn't seem worth the overhead yet.
279 Dyn(Arc<[GenericPredicate]>), 279 Dyn(Arc<[WhereClause]>),
280 280
281 /// A placeholder for a type which could not be computed; this is propagated 281 /// A placeholder for a type which could not be computed; this is propagated
282 /// to avoid useless error messages. Doubles as a placeholder where type 282 /// to avoid useless error messages. Doubles as a placeholder where type
@@ -564,7 +564,7 @@ impl TypeWalk for TraitRef {
564/// Like `generics::WherePredicate`, but with resolved types: A condition on the 564/// Like `generics::WherePredicate`, but with resolved types: A condition on the
565/// parameters of a generic item. 565/// parameters of a generic item.
566#[derive(Debug, Clone, PartialEq, Eq, Hash)] 566#[derive(Debug, Clone, PartialEq, Eq, Hash)]
567pub enum GenericPredicate { 567pub enum WhereClause {
568 /// The given trait needs to be implemented for its type parameters. 568 /// The given trait needs to be implemented for its type parameters.
569 Implemented(TraitRef), 569 Implemented(TraitRef),
570 /// An associated type bindings like in `Iterator<Item = T>`. 570 /// An associated type bindings like in `Iterator<Item = T>`.
@@ -574,32 +574,32 @@ pub enum GenericPredicate {
574 Error, 574 Error,
575} 575}
576 576
577impl GenericPredicate { 577impl WhereClause {
578 pub fn is_error(&self) -> bool { 578 pub fn is_error(&self) -> bool {
579 matches!(self, GenericPredicate::Error) 579 matches!(self, WhereClause::Error)
580 } 580 }
581 581
582 pub fn is_implemented(&self) -> bool { 582 pub fn is_implemented(&self) -> bool {
583 matches!(self, GenericPredicate::Implemented(_)) 583 matches!(self, WhereClause::Implemented(_))
584 } 584 }
585 585
586 pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> { 586 pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> {
587 match self { 587 match self {
588 GenericPredicate::Implemented(tr) => Some(tr.clone()), 588 WhereClause::Implemented(tr) => Some(tr.clone()),
589 GenericPredicate::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => { 589 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => {
590 Some(proj.trait_ref(db)) 590 Some(proj.trait_ref(db))
591 } 591 }
592 GenericPredicate::AliasEq(_) | GenericPredicate::Error => None, 592 WhereClause::AliasEq(_) | WhereClause::Error => None,
593 } 593 }
594 } 594 }
595} 595}
596 596
597impl TypeWalk for GenericPredicate { 597impl TypeWalk for WhereClause {
598 fn walk(&self, f: &mut impl FnMut(&Ty)) { 598 fn walk(&self, f: &mut impl FnMut(&Ty)) {
599 match self { 599 match self {
600 GenericPredicate::Implemented(trait_ref) => trait_ref.walk(f), 600 WhereClause::Implemented(trait_ref) => trait_ref.walk(f),
601 GenericPredicate::AliasEq(alias_eq) => alias_eq.walk(f), 601 WhereClause::AliasEq(alias_eq) => alias_eq.walk(f),
602 GenericPredicate::Error => {} 602 WhereClause::Error => {}
603 } 603 }
604 } 604 }
605 605
@@ -609,9 +609,9 @@ impl TypeWalk for GenericPredicate {
609 binders: DebruijnIndex, 609 binders: DebruijnIndex,
610 ) { 610 ) {
611 match self { 611 match self {
612 GenericPredicate::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders), 612 WhereClause::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders),
613 GenericPredicate::AliasEq(alias_eq) => alias_eq.walk_mut_binders(f, binders), 613 WhereClause::AliasEq(alias_eq) => alias_eq.walk_mut_binders(f, binders),
614 GenericPredicate::Error => {} 614 WhereClause::Error => {}
615 } 615 }
616 } 616 }
617} 617}
@@ -815,7 +815,7 @@ impl Ty {
815 pub fn dyn_trait_ref(&self) -> Option<&TraitRef> { 815 pub fn dyn_trait_ref(&self) -> Option<&TraitRef> {
816 match self.interned(&Interner) { 816 match self.interned(&Interner) {
817 TyKind::Dyn(bounds) => bounds.get(0).and_then(|b| match b { 817 TyKind::Dyn(bounds) => bounds.get(0).and_then(|b| match b {
818 GenericPredicate::Implemented(trait_ref) => Some(trait_ref), 818 WhereClause::Implemented(trait_ref) => Some(trait_ref),
819 _ => None, 819 _ => None,
820 }), 820 }),
821 _ => None, 821 _ => None,
@@ -894,7 +894,7 @@ impl Ty {
894 } 894 }
895 } 895 }
896 896
897 pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<GenericPredicate>> { 897 pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<WhereClause>> {
898 match self.interned(&Interner) { 898 match self.interned(&Interner) {
899 TyKind::OpaqueType(opaque_ty_id, ..) => { 899 TyKind::OpaqueType(opaque_ty_id, ..) => {
900 match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) { 900 match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) {
@@ -907,7 +907,7 @@ impl Ty {
907 // This is only used by type walking. 907 // This is only used by type walking.
908 // Parameters will be walked outside, and projection predicate is not used. 908 // Parameters will be walked outside, and projection predicate is not used.
909 // So just provide the Future trait. 909 // So just provide the Future trait.
910 let impl_bound = GenericPredicate::Implemented(TraitRef { 910 let impl_bound = WhereClause::Implemented(TraitRef {
911 trait_id: to_chalk_trait_id(future_trait), 911 trait_id: to_chalk_trait_id(future_trait),
912 substitution: Substitution::empty(), 912 substitution: Substitution::empty(),
913 }); 913 });
@@ -1166,7 +1166,7 @@ pub struct ReturnTypeImplTraits {
1166 1166
1167#[derive(Clone, PartialEq, Eq, Debug, Hash)] 1167#[derive(Clone, PartialEq, Eq, Debug, Hash)]
1168pub(crate) struct ReturnTypeImplTrait { 1168pub(crate) struct ReturnTypeImplTrait {
1169 pub(crate) bounds: Binders<Vec<GenericPredicate>>, 1169 pub(crate) bounds: Binders<Vec<WhereClause>>,
1170} 1170}
1171 1171
1172pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId { 1172pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId {
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(
881pub(crate) fn generic_predicates_for_param_query( 878pub(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(
966pub(crate) fn generic_predicates_query( 963pub(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);
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index ac7de7605..6feb64ceb 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -9,8 +9,8 @@ use hir_def::{lang_item::LangItemTarget, TraitId};
9use stdx::panic_context; 9use stdx::panic_context;
10 10
11use crate::{ 11use crate::{
12 db::HirDatabase, AliasTy, Canonical, DebruijnIndex, GenericPredicate, HirDisplay, Substitution, 12 db::HirDatabase, AliasTy, Canonical, DebruijnIndex, HirDisplay, Substitution, TraitRef, Ty,
13 TraitRef, Ty, TyKind, TypeWalk, 13 TyKind, TypeWalk, WhereClause,
14}; 14};
15 15
16use self::chalk::{from_chalk, Interner, ToChalk}; 16use self::chalk::{from_chalk, Interner, ToChalk};
@@ -96,11 +96,11 @@ pub enum Obligation {
96} 96}
97 97
98impl Obligation { 98impl Obligation {
99 pub fn from_predicate(predicate: GenericPredicate) -> Option<Obligation> { 99 pub fn from_predicate(predicate: WhereClause) -> Option<Obligation> {
100 match predicate { 100 match predicate {
101 GenericPredicate::Implemented(trait_ref) => Some(Obligation::Trait(trait_ref)), 101 WhereClause::Implemented(trait_ref) => Some(Obligation::Trait(trait_ref)),
102 GenericPredicate::AliasEq(alias_eq) => Some(Obligation::AliasEq(alias_eq)), 102 WhereClause::AliasEq(alias_eq) => Some(Obligation::AliasEq(alias_eq)),
103 GenericPredicate::Error => None, 103 WhereClause::Error => None,
104 } 104 }
105 } 105 }
106} 106}
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 080764e76..4144035cd 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -21,8 +21,8 @@ use crate::{
21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, 21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
22 to_assoc_type_id, to_chalk_trait_id, 22 to_assoc_type_id, to_chalk_trait_id,
23 utils::generics, 23 utils::generics,
24 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, 24 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, ProjectionTy,
25 GenericPredicate, ProjectionTy, Substitution, TraitRef, Ty, TyKind, 25 Substitution, TraitRef, Ty, TyKind, WhereClause,
26}; 26};
27use mapping::{ 27use mapping::{
28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, 28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
@@ -218,7 +218,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
218 // |-------------OpaqueTyDatumBound--------------| 218 // |-------------OpaqueTyDatumBound--------------|
219 // for<T> <Self> [Future<Self>, Future::Output<Self> = T] 219 // for<T> <Self> [Future<Self>, Future::Output<Self> = T]
220 // ^1 ^0 ^0 ^0 ^1 220 // ^1 ^0 ^0 ^0 ^1
221 let impl_bound = GenericPredicate::Implemented(TraitRef { 221 let impl_bound = WhereClause::Implemented(TraitRef {
222 trait_id: to_chalk_trait_id(future_trait), 222 trait_id: to_chalk_trait_id(future_trait),
223 // Self type as the first parameter. 223 // Self type as the first parameter.
224 substitution: Substitution::single( 224 substitution: Substitution::single(
@@ -229,7 +229,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
229 .intern(&Interner), 229 .intern(&Interner),
230 ), 230 ),
231 }); 231 });
232 let proj_bound = GenericPredicate::AliasEq(AliasEq { 232 let proj_bound = WhereClause::AliasEq(AliasEq {
233 alias: AliasTy::Projection(ProjectionTy { 233 alias: AliasTy::Projection(ProjectionTy {
234 associated_ty_id: to_assoc_type_id(future_output), 234 associated_ty_id: to_assoc_type_id(future_output),
235 // Self type as the first parameter. 235 // Self type as the first parameter.
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 62b779008..5756e9754 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -14,8 +14,8 @@ use crate::{
14 from_assoc_type_id, 14 from_assoc_type_id,
15 primitive::UintTy, 15 primitive::UintTy,
16 traits::{Canonical, Obligation}, 16 traits::{Canonical, Obligation},
17 AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, ProjectionTy, 17 AliasTy, CallableDefId, FnPointer, InEnvironment, OpaqueTy, ProjectionTy, Scalar, Substitution,
18 Scalar, Substitution, TraitRef, Ty, 18 TraitRef, Ty, WhereClause,
19}; 19};
20 20
21use super::interner::*; 21use super::interner::*;
@@ -304,28 +304,28 @@ impl ToChalk for TypeAliasAsValue {
304 } 304 }
305} 305}
306 306
307impl ToChalk for GenericPredicate { 307impl ToChalk for WhereClause {
308 type Chalk = chalk_ir::QuantifiedWhereClause<Interner>; 308 type Chalk = chalk_ir::QuantifiedWhereClause<Interner>;
309 309
310 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> { 310 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> {
311 match self { 311 match self {
312 GenericPredicate::Implemented(trait_ref) => { 312 WhereClause::Implemented(trait_ref) => {
313 let chalk_trait_ref = trait_ref.to_chalk(db); 313 let chalk_trait_ref = trait_ref.to_chalk(db);
314 let chalk_trait_ref = chalk_trait_ref.shifted_in(&Interner); 314 let chalk_trait_ref = chalk_trait_ref.shifted_in(&Interner);
315 make_binders(chalk_ir::WhereClause::Implemented(chalk_trait_ref), 0) 315 make_binders(chalk_ir::WhereClause::Implemented(chalk_trait_ref), 0)
316 } 316 }
317 GenericPredicate::AliasEq(alias_eq) => make_binders( 317 WhereClause::AliasEq(alias_eq) => make_binders(
318 chalk_ir::WhereClause::AliasEq(alias_eq.to_chalk(db).shifted_in(&Interner)), 318 chalk_ir::WhereClause::AliasEq(alias_eq.to_chalk(db).shifted_in(&Interner)),
319 0, 319 0,
320 ), 320 ),
321 GenericPredicate::Error => panic!("tried passing GenericPredicate::Error to Chalk"), 321 WhereClause::Error => panic!("tried passing GenericPredicate::Error to Chalk"),
322 } 322 }
323 } 323 }
324 324
325 fn from_chalk( 325 fn from_chalk(
326 db: &dyn HirDatabase, 326 db: &dyn HirDatabase,
327 where_clause: chalk_ir::QuantifiedWhereClause<Interner>, 327 where_clause: chalk_ir::QuantifiedWhereClause<Interner>,
328 ) -> GenericPredicate { 328 ) -> WhereClause {
329 // we don't produce any where clauses with binders and can't currently deal with them 329 // we don't produce any where clauses with binders and can't currently deal with them
330 match where_clause 330 match where_clause
331 .skip_binders() 331 .skip_binders()
@@ -333,11 +333,9 @@ impl ToChalk for GenericPredicate {
333 .shifted_out(&Interner) 333 .shifted_out(&Interner)
334 .expect("unexpected bound vars in where clause") 334 .expect("unexpected bound vars in where clause")
335 { 335 {
336 chalk_ir::WhereClause::Implemented(tr) => { 336 chalk_ir::WhereClause::Implemented(tr) => WhereClause::Implemented(from_chalk(db, tr)),
337 GenericPredicate::Implemented(from_chalk(db, tr))
338 }
339 chalk_ir::WhereClause::AliasEq(alias_eq) => { 337 chalk_ir::WhereClause::AliasEq(alias_eq) => {
340 GenericPredicate::AliasEq(from_chalk(db, alias_eq)) 338 WhereClause::AliasEq(from_chalk(db, alias_eq))
341 } 339 }
342 340
343 chalk_ir::WhereClause::LifetimeOutlives(_) => { 341 chalk_ir::WhereClause::LifetimeOutlives(_) => {
@@ -534,13 +532,13 @@ pub(super) fn convert_where_clauses(
534 532
535pub(super) fn generic_predicate_to_inline_bound( 533pub(super) fn generic_predicate_to_inline_bound(
536 db: &dyn HirDatabase, 534 db: &dyn HirDatabase,
537 pred: &GenericPredicate, 535 pred: &WhereClause,
538 self_ty: &Ty, 536 self_ty: &Ty,
539) -> Option<rust_ir::InlineBound<Interner>> { 537) -> Option<rust_ir::InlineBound<Interner>> {
540 // An InlineBound is like a GenericPredicate, except the self type is left out. 538 // An InlineBound is like a GenericPredicate, except the self type is left out.
541 // We don't have a special type for this, but Chalk does. 539 // We don't have a special type for this, but Chalk does.
542 match pred { 540 match pred {
543 GenericPredicate::Implemented(trait_ref) => { 541 WhereClause::Implemented(trait_ref) => {
544 if &trait_ref.substitution[0] != self_ty { 542 if &trait_ref.substitution[0] != self_ty {
545 // we can only convert predicates back to type bounds if they 543 // we can only convert predicates back to type bounds if they
546 // have the expected self type 544 // have the expected self type
@@ -553,7 +551,7 @@ pub(super) fn generic_predicate_to_inline_bound(
553 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; 551 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
554 Some(rust_ir::InlineBound::TraitBound(trait_bound)) 552 Some(rust_ir::InlineBound::TraitBound(trait_bound))
555 } 553 }
556 GenericPredicate::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { 554 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
557 if &projection_ty.substitution[0] != self_ty { 555 if &projection_ty.substitution[0] != self_ty {
558 return None; 556 return None;
559 } 557 }
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs
index b66243d48..1ec1ecd43 100644
--- a/crates/hir_ty/src/utils.rs
+++ b/crates/hir_ty/src/utils.rs
@@ -15,7 +15,7 @@ use hir_def::{
15}; 15};
16use hir_expand::name::{name, Name}; 16use hir_expand::name::{name, Name};
17 17
18use crate::{db::HirDatabase, GenericPredicate, TraitRef}; 18use crate::{db::HirDatabase, TraitRef, WhereClause};
19 19
20fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { 20fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> {
21 let resolver = trait_.resolver(db); 21 let resolver = trait_.resolver(db);
@@ -64,7 +64,7 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec<Tr
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 {
67 GenericPredicate::Implemented(tr) => Some(tr.clone()), 67 WhereClause::Implemented(tr) => Some(tr.clone()),
68 _ => None, 68 _ => None,
69 }) 69 })
70 }) 70 })