diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-20 20:17:14 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-20 20:17:14 +0000 |
commit | 62bc753f8b1957699288ceea90a4096667bf0ebc (patch) | |
tree | 3e21520683ad2fce54368614ff7e6b8b5ea62642 /crates/hir_ty/src/display.rs | |
parent | d0a787152d9f226707168f65ebfb215e23cedeed (diff) | |
parent | 0799288f0189c07907a30787e7d2f5f0bf960996 (diff) |
Merge #7732
7732: Don't lower TypeBound::Lifetime as GenericPredicate::Error r=flodiebold a=Veykril
Basically we just discard the typebound for now instead when lowering to `GenericPredicate`. I think this shouldn't have any other side effects?
Fixes #7683(hopefully for real this time)
I also played around with introducing `GenericPredicate::LifetimeOutlives` and `GenericPredicate::TypeOutlives`(see https://github.com/Veykril/rust-analyzer/commit/b9d69048451a5f2e9c5a72c800369bbeef36fdcf) but that won't fix this issue(at least not for now) due to lifetime predicate mismatches when resolving methods so I figure this is a good way to fix it for now.
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r-- | crates/hir_ty/src/display.rs | 29 |
1 files changed, 20 insertions, 9 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 | ||
630 | pub fn write_bounds_like_dyn_trait( | 627 | pub 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 | |||
641 | fn 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> { |