diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-07 19:51:36 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-07 19:51:36 +0100 |
commit | 3191a93185b34c6deebca2aad0584d2840ad6d43 (patch) | |
tree | 1fad465381a5b9a9d0b77dbf68a246db1835f511 /crates/hir_ty/src/display.rs | |
parent | 6379839c8203b6fbc9af947997a7f73a36ef15a2 (diff) | |
parent | dc116f7ce2192433c9491441a11d294e7d294fbf (diff) |
Merge #8409
8409: Various remaining fixes for Chalk IR move r=flodiebold a=flodiebold
CC #8313
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r-- | crates/hir_ty/src/display.rs | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 9e6bbcdf1..e0ca96c6d 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -24,7 +24,7 @@ use crate::{ | |||
24 | traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, | 24 | traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, |
25 | CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, | 25 | CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, |
26 | LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, | 26 | LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, |
27 | QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause, | 27 | QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | pub struct HirFormatter<'a> { | 30 | pub struct HirFormatter<'a> { |
@@ -616,12 +616,12 @@ impl HirDisplay for Ty { | |||
616 | .map(|pred| pred.clone().substitute(&Interner, &substs)) | 616 | .map(|pred| pred.clone().substitute(&Interner, &substs)) |
617 | .filter(|wc| match &wc.skip_binders() { | 617 | .filter(|wc| match &wc.skip_binders() { |
618 | WhereClause::Implemented(tr) => { | 618 | WhereClause::Implemented(tr) => { |
619 | tr.self_type_parameter(&Interner) == self | 619 | &tr.self_type_parameter(&Interner) == self |
620 | } | 620 | } |
621 | WhereClause::AliasEq(AliasEq { | 621 | WhereClause::AliasEq(AliasEq { |
622 | alias: AliasTy::Projection(proj), | 622 | alias: AliasTy::Projection(proj), |
623 | ty: _, | 623 | ty: _, |
624 | }) => proj.self_type_parameter(&Interner) == self, | 624 | }) => &proj.self_type_parameter(&Interner) == self, |
625 | _ => false, | 625 | _ => false, |
626 | }) | 626 | }) |
627 | .collect::<Vec<_>>(); | 627 | .collect::<Vec<_>>(); |
@@ -745,7 +745,7 @@ fn write_bounds_like_dyn_trait( | |||
745 | // existential) here, which is the only thing that's | 745 | // existential) here, which is the only thing that's |
746 | // possible in actual Rust, and hence don't print it | 746 | // possible in actual Rust, and hence don't print it |
747 | write!(f, "{}", f.db.trait_data(trait_).name)?; | 747 | write!(f, "{}", f.db.trait_data(trait_).name)?; |
748 | if let [_, params @ ..] = &*trait_ref.substitution.interned() { | 748 | if let [_, params @ ..] = &*trait_ref.substitution.interned().as_slice() { |
749 | if is_fn_trait { | 749 | if is_fn_trait { |
750 | if let Some(args) = | 750 | if let Some(args) = |
751 | params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple()) | 751 | params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple()) |
@@ -792,31 +792,29 @@ fn write_bounds_like_dyn_trait( | |||
792 | Ok(()) | 792 | Ok(()) |
793 | } | 793 | } |
794 | 794 | ||
795 | impl TraitRef { | 795 | fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { |
796 | fn hir_fmt_ext(&self, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { | 796 | if f.should_truncate() { |
797 | if f.should_truncate() { | 797 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
798 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | 798 | } |
799 | } | ||
800 | 799 | ||
801 | self.self_type_parameter(&Interner).hir_fmt(f)?; | 800 | tr.self_type_parameter(&Interner).hir_fmt(f)?; |
802 | if use_as { | 801 | if use_as { |
803 | write!(f, " as ")?; | 802 | write!(f, " as ")?; |
804 | } else { | 803 | } else { |
805 | write!(f, ": ")?; | 804 | write!(f, ": ")?; |
806 | } | ||
807 | write!(f, "{}", f.db.trait_data(self.hir_trait_id()).name)?; | ||
808 | if self.substitution.len(&Interner) > 1 { | ||
809 | write!(f, "<")?; | ||
810 | f.write_joined(&self.substitution.interned()[1..], ", ")?; | ||
811 | write!(f, ">")?; | ||
812 | } | ||
813 | Ok(()) | ||
814 | } | 805 | } |
806 | write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?; | ||
807 | if tr.substitution.len(&Interner) > 1 { | ||
808 | write!(f, "<")?; | ||
809 | f.write_joined(&tr.substitution.interned()[1..], ", ")?; | ||
810 | write!(f, ">")?; | ||
811 | } | ||
812 | Ok(()) | ||
815 | } | 813 | } |
816 | 814 | ||
817 | impl HirDisplay for TraitRef { | 815 | impl HirDisplay for TraitRef { |
818 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 816 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
819 | self.hir_fmt_ext(f, false) | 817 | fmt_trait_ref(self, f, false) |
820 | } | 818 | } |
821 | } | 819 | } |
822 | 820 | ||
@@ -830,7 +828,7 @@ impl HirDisplay for WhereClause { | |||
830 | WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, | 828 | WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, |
831 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { | 829 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { |
832 | write!(f, "<")?; | 830 | write!(f, "<")?; |
833 | projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; | 831 | fmt_trait_ref(&projection_ty.trait_ref(f.db), f, true)?; |
834 | write!( | 832 | write!( |
835 | f, | 833 | f, |
836 | ">::{} = ", | 834 | ">::{} = ", |