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