diff options
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r-- | crates/hir_ty/src/lower.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 44bd95a9a..ca06c9fe2 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -31,8 +31,8 @@ use crate::{ | |||
31 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, | 31 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, |
32 | make_mut_slice, variant_data, | 32 | make_mut_slice, variant_data, |
33 | }, | 33 | }, |
34 | Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, OpaqueTy, | 34 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, |
35 | OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, | 35 | OpaqueTy, OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, |
36 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, | 36 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, |
37 | }; | 37 | }; |
38 | 38 | ||
@@ -157,7 +157,7 @@ impl Ty { | |||
157 | } | 157 | } |
158 | TypeRef::RawPtr(inner, mutability) => { | 158 | TypeRef::RawPtr(inner, mutability) => { |
159 | let inner_ty = Ty::from_hir(ctx, inner); | 159 | let inner_ty = Ty::from_hir(ctx, inner); |
160 | Ty::RawPtr(*mutability, Substs::single(inner_ty)) | 160 | Ty::Raw(*mutability, Substs::single(inner_ty)) |
161 | } | 161 | } |
162 | TypeRef::Array(inner) => { | 162 | TypeRef::Array(inner) => { |
163 | let inner_ty = Ty::from_hir(ctx, inner); | 163 | let inner_ty = Ty::from_hir(ctx, inner); |
@@ -181,7 +181,7 @@ impl Ty { | |||
181 | }) | 181 | }) |
182 | } | 182 | } |
183 | TypeRef::DynTrait(bounds) => { | 183 | TypeRef::DynTrait(bounds) => { |
184 | let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); | 184 | let self_ty = Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)); |
185 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { | 185 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { |
186 | bounds | 186 | bounds |
187 | .iter() | 187 | .iter() |
@@ -225,7 +225,10 @@ impl Ty { | |||
225 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); | 225 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); |
226 | let generics = generics(ctx.db.upcast(), func.into()); | 226 | let generics = generics(ctx.db.upcast(), func.into()); |
227 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); | 227 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); |
228 | Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) | 228 | Ty::Alias(AliasTy::Opaque(OpaqueTy { |
229 | opaque_ty_id: impl_trait_id, | ||
230 | parameters, | ||
231 | })) | ||
229 | } | 232 | } |
230 | ImplTraitLoweringMode::Param => { | 233 | ImplTraitLoweringMode::Param => { |
231 | let idx = ctx.impl_trait_counter.get(); | 234 | let idx = ctx.impl_trait_counter.get(); |
@@ -256,7 +259,7 @@ impl Ty { | |||
256 | } else { | 259 | } else { |
257 | (0, 0, 0, 0) | 260 | (0, 0, 0, 0) |
258 | }; | 261 | }; |
259 | Ty::Bound(BoundVar::new( | 262 | Ty::BoundVar(BoundVar::new( |
260 | ctx.in_binders, | 263 | ctx.in_binders, |
261 | idx as usize + parent_params + self_params + list_params, | 264 | idx as usize + parent_params + self_params + list_params, |
262 | )) | 265 | )) |
@@ -328,7 +331,7 @@ impl Ty { | |||
328 | TypeNs::TraitId(trait_) => { | 331 | TypeNs::TraitId(trait_) => { |
329 | // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there | 332 | // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there |
330 | let self_ty = if remaining_segments.len() == 0 { | 333 | let self_ty = if remaining_segments.len() == 0 { |
331 | Some(Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0))) | 334 | Some(Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))) |
332 | } else { | 335 | } else { |
333 | None | 336 | None |
334 | }; | 337 | }; |
@@ -344,10 +347,10 @@ impl Ty { | |||
344 | match found { | 347 | match found { |
345 | Some((super_trait_ref, associated_ty)) => { | 348 | Some((super_trait_ref, associated_ty)) => { |
346 | // FIXME handle type parameters on the segment | 349 | // FIXME handle type parameters on the segment |
347 | Ty::Projection(ProjectionTy { | 350 | Ty::Alias(AliasTy::Projection(ProjectionTy { |
348 | associated_ty, | 351 | associated_ty, |
349 | parameters: super_trait_ref.substs, | 352 | parameters: super_trait_ref.substs, |
350 | }) | 353 | })) |
351 | } | 354 | } |
352 | None => { | 355 | None => { |
353 | // FIXME: report error (associated type not found) | 356 | // FIXME: report error (associated type not found) |
@@ -371,7 +374,7 @@ impl Ty { | |||
371 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 374 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), |
372 | TypeParamLoweringMode::Variable => { | 375 | TypeParamLoweringMode::Variable => { |
373 | let idx = generics.param_idx(param_id).expect("matching generics"); | 376 | let idx = generics.param_idx(param_id).expect("matching generics"); |
374 | Ty::Bound(BoundVar::new(ctx.in_binders, idx)) | 377 | Ty::BoundVar(BoundVar::new(ctx.in_binders, idx)) |
375 | } | 378 | } |
376 | } | 379 | } |
377 | } | 380 | } |
@@ -469,10 +472,10 @@ impl Ty { | |||
469 | // associated_type_shorthand_candidates does not do that | 472 | // associated_type_shorthand_candidates does not do that |
470 | let substs = substs.shift_bound_vars(ctx.in_binders); | 473 | let substs = substs.shift_bound_vars(ctx.in_binders); |
471 | // FIXME handle type parameters on the segment | 474 | // FIXME handle type parameters on the segment |
472 | return Some(Ty::Projection(ProjectionTy { | 475 | return Some(Ty::Alias(AliasTy::Projection(ProjectionTy { |
473 | associated_ty, | 476 | associated_ty, |
474 | parameters: substs, | 477 | parameters: substs, |
475 | })); | 478 | }))); |
476 | } | 479 | } |
477 | 480 | ||
478 | None | 481 | None |
@@ -673,7 +676,7 @@ impl GenericPredicate { | |||
673 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 676 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), |
674 | TypeParamLoweringMode::Variable => { | 677 | TypeParamLoweringMode::Variable => { |
675 | let idx = generics.param_idx(param_id).expect("matching generics"); | 678 | let idx = generics.param_idx(param_id).expect("matching generics"); |
676 | Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, idx)) | 679 | Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx)) |
677 | } | 680 | } |
678 | } | 681 | } |
679 | } | 682 | } |
@@ -747,7 +750,7 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
747 | preds.extend(GenericPredicate::from_type_bound( | 750 | preds.extend(GenericPredicate::from_type_bound( |
748 | ctx, | 751 | ctx, |
749 | bound, | 752 | bound, |
750 | Ty::Projection(projection_ty.clone()), | 753 | Ty::Alias(AliasTy::Projection(projection_ty.clone())), |
751 | )); | 754 | )); |
752 | } | 755 | } |
753 | preds | 756 | preds |
@@ -757,7 +760,7 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
757 | impl ReturnTypeImplTrait { | 760 | impl ReturnTypeImplTrait { |
758 | fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { | 761 | fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { |
759 | mark::hit!(lower_rpit); | 762 | mark::hit!(lower_rpit); |
760 | let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); | 763 | let self_ty = Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)); |
761 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { | 764 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { |
762 | bounds | 765 | bounds |
763 | .iter() | 766 | .iter() |
@@ -981,7 +984,7 @@ pub(crate) fn generic_defaults_query( | |||
981 | // Each default can only refer to previous parameters. | 984 | // Each default can only refer to previous parameters. |
982 | ty.walk_mut_binders( | 985 | ty.walk_mut_binders( |
983 | &mut |ty, binders| match ty { | 986 | &mut |ty, binders| match ty { |
984 | Ty::Bound(BoundVar { debruijn, index }) if *debruijn == binders => { | 987 | Ty::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => { |
985 | if *index >= idx { | 988 | if *index >= idx { |
986 | // type variable default referring to parameter coming | 989 | // type variable default referring to parameter coming |
987 | // after it. This is forbidden (FIXME: report | 990 | // after it. This is forbidden (FIXME: report |