diff options
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r-- | crates/hir_ty/src/lower.rs | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index e6903e189..a035686bc 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -8,7 +8,7 @@ | |||
8 | use std::{iter, sync::Arc}; | 8 | use std::{iter, sync::Arc}; |
9 | 9 | ||
10 | use base_db::CrateId; | 10 | use base_db::CrateId; |
11 | use chalk_ir::{cast::Cast, Mutability, Safety}; | 11 | use chalk_ir::{cast::Cast, fold::Shift, interner::HasInterner, Mutability, Safety}; |
12 | use hir_def::{ | 12 | use hir_def::{ |
13 | adt::StructKind, | 13 | adt::StructKind, |
14 | builtin_type::BuiltinType, | 14 | builtin_type::BuiltinType, |
@@ -27,15 +27,16 @@ use stdx::impl_from; | |||
27 | 27 | ||
28 | use crate::{ | 28 | use crate::{ |
29 | db::HirDatabase, | 29 | db::HirDatabase, |
30 | dummy_usize_const, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx, | 30 | dummy_usize_const, |
31 | traits::chalk::{Interner, ToChalk}, | 31 | mapping::ToChalk, |
32 | static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx, | ||
32 | utils::{ | 33 | utils::{ |
33 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics, | 34 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics, |
34 | }, | 35 | }, |
35 | AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig, | 36 | AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig, |
36 | FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, | 37 | FnSubst, ImplTraitId, Interner, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, |
37 | QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, | 38 | QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, |
38 | TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, TypeWalk, WhereClause, | 39 | TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause, |
39 | }; | 40 | }; |
40 | 41 | ||
41 | #[derive(Debug)] | 42 | #[derive(Debug)] |
@@ -488,7 +489,7 @@ impl<'a> TyLoweringContext<'a> { | |||
488 | }; | 489 | }; |
489 | // We need to shift in the bound vars, since | 490 | // We need to shift in the bound vars, since |
490 | // associated_type_shorthand_candidates does not do that | 491 | // associated_type_shorthand_candidates does not do that |
491 | let substs = substs.shifted_in_from(self.in_binders); | 492 | let substs = substs.shifted_in_from(&Interner, self.in_binders); |
492 | // FIXME handle type parameters on the segment | 493 | // FIXME handle type parameters on the segment |
493 | return Some( | 494 | return Some( |
494 | TyKind::Alias(AliasTy::Projection(ProjectionTy { | 495 | TyKind::Alias(AliasTy::Projection(ProjectionTy { |
@@ -847,7 +848,7 @@ pub fn associated_type_shorthand_candidates<R>( | |||
847 | // FIXME: how to correctly handle higher-ranked bounds here? | 848 | // FIXME: how to correctly handle higher-ranked bounds here? |
848 | WhereClause::Implemented(tr) => search( | 849 | WhereClause::Implemented(tr) => search( |
849 | tr.clone() | 850 | tr.clone() |
850 | .shifted_out_to(DebruijnIndex::ONE) | 851 | .shifted_out_to(&Interner, DebruijnIndex::ONE) |
851 | .expect("FIXME unexpected higher-ranked trait bound"), | 852 | .expect("FIXME unexpected higher-ranked trait bound"), |
852 | ), | 853 | ), |
853 | _ => None, | 854 | _ => None, |
@@ -950,8 +951,7 @@ pub(crate) fn trait_environment_query( | |||
950 | traits_in_scope | 951 | traits_in_scope |
951 | .push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id())); | 952 | .push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id())); |
952 | } | 953 | } |
953 | let program_clause: chalk_ir::ProgramClause<Interner> = | 954 | let program_clause: chalk_ir::ProgramClause<Interner> = pred.clone().cast(&Interner); |
954 | pred.clone().to_chalk(db).cast(&Interner); | ||
955 | clauses.push(program_clause.into_from_env_clause(&Interner)); | 955 | clauses.push(program_clause.into_from_env_clause(&Interner)); |
956 | } | 956 | } |
957 | } | 957 | } |
@@ -974,7 +974,7 @@ pub(crate) fn trait_environment_query( | |||
974 | let substs = TyBuilder::type_params_subst(db, trait_id); | 974 | let substs = TyBuilder::type_params_subst(db, trait_id); |
975 | let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; | 975 | let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; |
976 | let pred = WhereClause::Implemented(trait_ref); | 976 | let pred = WhereClause::Implemented(trait_ref); |
977 | let program_clause: chalk_ir::ProgramClause<Interner> = pred.to_chalk(db).cast(&Interner); | 977 | let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(&Interner); |
978 | clauses.push(program_clause.into_from_env_clause(&Interner)); | 978 | clauses.push(program_clause.into_from_env_clause(&Interner)); |
979 | } | 979 | } |
980 | 980 | ||
@@ -1016,22 +1016,16 @@ pub(crate) fn generic_defaults_query( | |||
1016 | p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t)); | 1016 | p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t)); |
1017 | 1017 | ||
1018 | // Each default can only refer to previous parameters. | 1018 | // Each default can only refer to previous parameters. |
1019 | ty = ty.fold_binders( | 1019 | ty = crate::fold_free_vars(ty, |bound, binders| { |
1020 | &mut |ty, binders| match ty.kind(&Interner) { | 1020 | if bound.index >= idx && bound.debruijn == DebruijnIndex::INNERMOST { |
1021 | TyKind::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => { | 1021 | // type variable default referring to parameter coming |
1022 | if *index >= idx { | 1022 | // after it. This is forbidden (FIXME: report |
1023 | // type variable default referring to parameter coming | 1023 | // diagnostic) |
1024 | // after it. This is forbidden (FIXME: report | 1024 | TyKind::Error.intern(&Interner) |
1025 | // diagnostic) | 1025 | } else { |
1026 | TyKind::Error.intern(&Interner) | 1026 | bound.shifted_in_from(binders).to_ty(&Interner) |
1027 | } else { | 1027 | } |
1028 | ty | 1028 | }); |
1029 | } | ||
1030 | } | ||
1031 | _ => ty, | ||
1032 | }, | ||
1033 | DebruijnIndex::INNERMOST, | ||
1034 | ); | ||
1035 | 1029 | ||
1036 | crate::make_only_type_binders(idx, ty) | 1030 | crate::make_only_type_binders(idx, ty) |
1037 | }) | 1031 | }) |
@@ -1307,6 +1301,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut | |||
1307 | } | 1301 | } |
1308 | } | 1302 | } |
1309 | 1303 | ||
1310 | fn make_binders<T>(generics: &Generics, value: T) -> Binders<T> { | 1304 | fn make_binders<T: HasInterner<Interner = Interner>>(generics: &Generics, value: T) -> Binders<T> { |
1311 | crate::make_only_type_binders(generics.len(), value) | 1305 | crate::make_only_type_binders(generics.len(), value) |
1312 | } | 1306 | } |