aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/lower.rs')
-rw-r--r--crates/ra_hir_ty/src/lower.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index d7f250783..6c7bbc448 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -29,8 +29,8 @@ use crate::{
29 all_super_traits, associated_type_by_name_including_super_traits, generics, make_mut_slice, 29 all_super_traits, associated_type_by_name_including_super_traits, generics, make_mut_slice,
30 variant_data, 30 variant_data,
31 }, 31 },
32 Binders, FnSig, GenericPredicate, PolyFnSig, ProjectionPredicate, ProjectionTy, Substs, 32 Binders, BoundVar, DebruijnIndex, FnSig, GenericPredicate, PolyFnSig, ProjectionPredicate,
33 TraitEnvironment, TraitRef, Ty, TypeCtor, 33 ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeCtor,
34}; 34};
35 35
36#[derive(Debug)] 36#[derive(Debug)]
@@ -131,7 +131,7 @@ impl Ty {
131 Ty::apply(TypeCtor::FnPtr { num_args: sig.len() as u16 - 1 }, sig) 131 Ty::apply(TypeCtor::FnPtr { num_args: sig.len() as u16 - 1 }, sig)
132 } 132 }
133 TypeRef::DynTrait(bounds) => { 133 TypeRef::DynTrait(bounds) => {
134 let self_ty = Ty::Bound(0); 134 let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0));
135 let predicates = bounds 135 let predicates = bounds
136 .iter() 136 .iter()
137 .flat_map(|b| GenericPredicate::from_type_bound(ctx, b, self_ty.clone())) 137 .flat_map(|b| GenericPredicate::from_type_bound(ctx, b, self_ty.clone()))
@@ -141,7 +141,7 @@ impl Ty {
141 TypeRef::ImplTrait(bounds) => { 141 TypeRef::ImplTrait(bounds) => {
142 match ctx.impl_trait_mode { 142 match ctx.impl_trait_mode {
143 ImplTraitLoweringMode::Opaque => { 143 ImplTraitLoweringMode::Opaque => {
144 let self_ty = Ty::Bound(0); 144 let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0));
145 let predicates = bounds 145 let predicates = bounds
146 .iter() 146 .iter()
147 .flat_map(|b| { 147 .flat_map(|b| {
@@ -177,12 +177,10 @@ impl Ty {
177 } else { 177 } else {
178 (0, 0, 0, 0) 178 (0, 0, 0, 0)
179 }; 179 };
180 Ty::Bound( 180 Ty::Bound(BoundVar::new(
181 idx as u32 181 DebruijnIndex::INNERMOST,
182 + parent_params as u32 182 idx as usize + parent_params + self_params + list_params,
183 + self_params as u32 183 ))
184 + list_params as u32,
185 )
186 } 184 }
187 ImplTraitLoweringMode::Disallowed => { 185 ImplTraitLoweringMode::Disallowed => {
188 // FIXME: report error 186 // FIXME: report error
@@ -249,7 +247,11 @@ impl Ty {
249 let ty = match resolution { 247 let ty = match resolution {
250 TypeNs::TraitId(trait_) => { 248 TypeNs::TraitId(trait_) => {
251 // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there 249 // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there
252 let self_ty = if remaining_segments.len() == 0 { Some(Ty::Bound(0)) } else { None }; 250 let self_ty = if remaining_segments.len() == 0 {
251 Some(Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)))
252 } else {
253 None
254 };
253 let trait_ref = 255 let trait_ref =
254 TraitRef::from_resolved_path(ctx, trait_, resolved_segment, self_ty); 256 TraitRef::from_resolved_path(ctx, trait_, resolved_segment, self_ty);
255 let ty = if remaining_segments.len() == 1 { 257 let ty = if remaining_segments.len() == 1 {
@@ -289,7 +291,7 @@ impl Ty {
289 TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), 291 TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id),
290 TypeParamLoweringMode::Variable => { 292 TypeParamLoweringMode::Variable => {
291 let idx = generics.param_idx(param_id).expect("matching generics"); 293 let idx = generics.param_idx(param_id).expect("matching generics");
292 Ty::Bound(idx) 294 Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, idx))
293 } 295 }
294 } 296 }
295 } 297 }
@@ -558,7 +560,7 @@ impl GenericPredicate {
558 TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), 560 TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id),
559 TypeParamLoweringMode::Variable => { 561 TypeParamLoweringMode::Variable => {
560 let idx = generics.param_idx(param_id).expect("matching generics"); 562 let idx = generics.param_idx(param_id).expect("matching generics");
561 Ty::Bound(idx) 563 Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, idx))
562 } 564 }
563 } 565 }
564 } 566 }