aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/display.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-03-20 09:46:36 +0000
committerFlorian Diebold <[email protected]>2021-03-20 09:46:36 +0000
commit7a5fb37cf12f4e25ce1ba7e464dd257408444bfb (patch)
treefedc1b02375558b9bd027a318c4bc131784d58c6 /crates/hir_ty/src/display.rs
parent8b16af590dd3d241bec07f69f4d4dadae9a4b523 (diff)
Rename GenericPredicate -> WhereClause
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r--crates/hir_ty/src/display.rs29
1 files changed, 13 insertions, 16 deletions
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 }