aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/lower.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-30 14:23:18 +0000
committerGitHub <[email protected]>2019-11-30 14:23:18 +0000
commit9712889ee4c6cffa37c2ace5da9b00bf29adab56 (patch)
tree0471718f620bfdcb207387f6ae58bdfa5ca47e4e /crates/ra_hir_ty/src/lower.rs
parent7cecd0f331419439417f98d92b839c9aaa06ed86 (diff)
parent1c622e9fed97de7711da7b5bffec0fa4b19d7500 (diff)
Merge #2453
2453: Handle various cycles r=matklad a=flodiebold - handle `impl Trait<Self> for SomeType`, which is allowed. This necessitated splitting the `impl_ty` query, but I think the result actually makes a lot of code nicer. This should fix #2446. - add recovery for `impl Trait for SomeType<Self>` - add recovery for `type Type = Foo<Type>` - add recovery for cycles in generic param env Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/lower.rs')
-rw-r--r--crates/ra_hir_ty/src/lower.rs49
1 files changed, 35 insertions, 14 deletions
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index 091c60f4f..32569ac66 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -27,8 +27,8 @@ use crate::{
27 all_super_traits, associated_type_by_name_including_super_traits, make_mut_slice, 27 all_super_traits, associated_type_by_name_including_super_traits, make_mut_slice,
28 variant_data, 28 variant_data,
29 }, 29 },
30 FnSig, GenericPredicate, ImplTy, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, 30 FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef,
31 TraitRef, Ty, TypeCtor, TypeWalk, 31 Ty, TypeCtor, TypeWalk,
32}; 32};
33 33
34impl Ty { 34impl Ty {
@@ -179,7 +179,7 @@ impl Ty {
179 let name = resolved_segment.name.clone(); 179 let name = resolved_segment.name.clone();
180 Ty::Param { idx, name } 180 Ty::Param { idx, name }
181 } 181 }
182 TypeNs::SelfType(impl_id) => db.impl_ty(impl_id).self_type().clone(), 182 TypeNs::SelfType(impl_id) => db.impl_self_ty(impl_id).clone(),
183 TypeNs::AdtSelfType(adt) => db.ty(adt.into()), 183 TypeNs::AdtSelfType(adt) => db.ty(adt.into()),
184 184
185 TypeNs::AdtId(it) => Ty::from_hir_path_inner(db, resolver, resolved_segment, it.into()), 185 TypeNs::AdtId(it) => Ty::from_hir_path_inner(db, resolver, resolved_segment, it.into()),
@@ -532,6 +532,15 @@ pub(crate) fn generic_predicates_for_param_query(
532 .collect() 532 .collect()
533} 533}
534 534
535pub(crate) fn generic_predicates_for_param_recover(
536 _db: &impl HirDatabase,
537 _cycle: &[String],
538 _def: &GenericDefId,
539 _param_idx: &u32,
540) -> Arc<[GenericPredicate]> {
541 Arc::new([])
542}
543
535impl TraitEnvironment { 544impl TraitEnvironment {
536 pub fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> { 545 pub fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> {
537 let predicates = resolver 546 let predicates = resolver
@@ -733,6 +742,11 @@ pub(crate) fn ty_query(db: &impl HirDatabase, def: TyDefId) -> Ty {
733 TyDefId::TypeAliasId(it) => type_for_type_alias(db, it), 742 TyDefId::TypeAliasId(it) => type_for_type_alias(db, it),
734 } 743 }
735} 744}
745
746pub(crate) fn ty_recover(_db: &impl HirDatabase, _cycle: &[String], _def: &TyDefId) -> Ty {
747 Ty::Unknown
748}
749
736pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty { 750pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty {
737 match def { 751 match def {
738 ValueTyDefId::FunctionId(it) => type_for_fn(db, it), 752 ValueTyDefId::FunctionId(it) => type_for_fn(db, it),
@@ -743,17 +757,24 @@ pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty {
743 } 757 }
744} 758}
745 759
746pub(crate) fn impl_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> ImplTy { 760pub(crate) fn impl_self_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> Ty {
747 let impl_data = db.impl_data(impl_id); 761 let impl_data = db.impl_data(impl_id);
748 let resolver = impl_id.resolver(db); 762 let resolver = impl_id.resolver(db);
749 let self_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); 763 Ty::from_hir(db, &resolver, &impl_data.target_type)
750 match impl_data.target_trait.as_ref() { 764}
751 Some(trait_ref) => { 765
752 match TraitRef::from_hir(db, &resolver, trait_ref, Some(self_ty.clone())) { 766pub(crate) fn impl_self_ty_recover(
753 Some(it) => ImplTy::TraitRef(it), 767 _db: &impl HirDatabase,
754 None => ImplTy::Inherent(self_ty), 768 _cycle: &[String],
755 } 769 _impl_id: &ImplId,
756 } 770) -> Ty {
757 None => ImplTy::Inherent(self_ty), 771 Ty::Unknown
758 } 772}
773
774pub(crate) fn impl_trait_query(db: &impl HirDatabase, impl_id: ImplId) -> Option<TraitRef> {
775 let impl_data = db.impl_data(impl_id);
776 let resolver = impl_id.resolver(db);
777 let self_ty = db.impl_self_ty(impl_id);
778 let target_trait = impl_data.target_trait.as_ref()?;
779 TraitRef::from_hir(db, &resolver, target_trait, Some(self_ty.clone()))
759} 780}