aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/display.rs29
-rw-r--r--crates/hir_ty/src/tests/traits.rs4
2 files changed, 22 insertions, 11 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 38a043c48..271fcbfaf 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -467,8 +467,7 @@ impl HirDisplay for ApplicationTy {
467 .as_ref() 467 .as_ref()
468 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); 468 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
469 let bounds = data.subst(&self.parameters); 469 let bounds = data.subst(&self.parameters);
470 write!(f, "impl ")?; 470 write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?;
471 write_bounds_like_dyn_trait(&bounds.value, f)?;
472 // FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution 471 // FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution
473 } 472 }
474 OpaqueTyId::AsyncBlockTypeImplTrait(..) => { 473 OpaqueTyId::AsyncBlockTypeImplTrait(..) => {
@@ -548,10 +547,10 @@ impl HirDisplay for Ty {
548 write!(f, "{}", param_data.name.clone().unwrap_or_else(Name::missing))? 547 write!(f, "{}", param_data.name.clone().unwrap_or_else(Name::missing))?
549 } 548 }
550 TypeParamProvenance::ArgumentImplTrait => { 549 TypeParamProvenance::ArgumentImplTrait => {
551 write!(f, "impl ")?;
552 let bounds = f.db.generic_predicates_for_param(*id); 550 let bounds = f.db.generic_predicates_for_param(*id);
553 let substs = Substs::type_params_for_generics(&generics); 551 let substs = Substs::type_params_for_generics(&generics);
554 write_bounds_like_dyn_trait( 552 write_bounds_like_dyn_trait_with_prefix(
553 "impl",
555 &bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), 554 &bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(),
556 f, 555 f,
557 )?; 556 )?;
@@ -560,8 +559,7 @@ impl HirDisplay for Ty {
560 } 559 }
561 Ty::Bound(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index)?, 560 Ty::Bound(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index)?,
562 Ty::Dyn(predicates) => { 561 Ty::Dyn(predicates) => {
563 write!(f, "dyn ")?; 562 write_bounds_like_dyn_trait_with_prefix("dyn", predicates, f)?;
564 write_bounds_like_dyn_trait(predicates, f)?;
565 } 563 }
566 Ty::Opaque(opaque_ty) => { 564 Ty::Opaque(opaque_ty) => {
567 match opaque_ty.opaque_ty_id { 565 match opaque_ty.opaque_ty_id {
@@ -572,8 +570,7 @@ impl HirDisplay for Ty {
572 .as_ref() 570 .as_ref()
573 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); 571 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
574 let bounds = data.subst(&opaque_ty.parameters); 572 let bounds = data.subst(&opaque_ty.parameters);
575 write!(f, "impl ")?; 573 write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?;
576 write_bounds_like_dyn_trait(&bounds.value, f)?;
577 } 574 }
578 OpaqueTyId::AsyncBlockTypeImplTrait(..) => { 575 OpaqueTyId::AsyncBlockTypeImplTrait(..) => {
579 write!(f, "{{async block}}")?; 576 write!(f, "{{async block}}")?;
@@ -627,7 +624,21 @@ fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = Trai
627 ArrayVec::from(fn_traits).into_iter().flatten().flat_map(|it| it.as_trait()) 624 ArrayVec::from(fn_traits).into_iter().flatten().flat_map(|it| it.as_trait())
628} 625}
629 626
630pub fn write_bounds_like_dyn_trait( 627pub fn write_bounds_like_dyn_trait_with_prefix(
628 prefix: &str,
629 predicates: &[GenericPredicate],
630 f: &mut HirFormatter,
631) -> Result<(), HirDisplayError> {
632 write!(f, "{}", prefix)?;
633 if !predicates.is_empty() {
634 write!(f, " ")?;
635 write_bounds_like_dyn_trait(predicates, f)
636 } else {
637 Ok(())
638 }
639}
640
641fn write_bounds_like_dyn_trait(
631 predicates: &[GenericPredicate], 642 predicates: &[GenericPredicate],
632 f: &mut HirFormatter, 643 f: &mut HirFormatter,
633) -> Result<(), HirDisplayError> { 644) -> Result<(), HirDisplayError> {
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 744fb5ff2..1298e5a88 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -1410,9 +1410,9 @@ fn weird_bounds() {
1410 "#, 1410 "#,
1411 expect![[r#" 1411 expect![[r#"
1412 23..24 'a': impl Trait 1412 23..24 'a': impl Trait
1413 50..51 'b': impl 1413 50..51 'b': impl
1414 69..70 'c': impl Trait 1414 69..70 'c': impl Trait
1415 86..87 'd': impl 1415 86..87 'd': impl
1416 107..108 'e': impl {error} 1416 107..108 'e': impl {error}
1417 123..124 'f': impl Trait + {error} 1417 123..124 'f': impl Trait + {error}
1418 147..149 '{}': () 1418 147..149 '{}': ()