@@ -6,8 +6,8 @@ use chalk_ir::{
66 WellFormed , cast:: Cast , fold:: Shift , interner:: HasInterner ,
77} ;
88use hir_def:: {
9- CallableDefId , ConstParamId , FunctionId , GeneralConstId , LifetimeParamId , TypeAliasId ,
10- TypeOrConstParamId , TypeParamId , signatures:: TraitFlags ,
9+ CallableDefId , ConstParamId , FunctionId , GeneralConstId , GenericDefId , LifetimeParamId ,
10+ TypeAliasId , TypeOrConstParamId , TypeParamId , signatures:: TraitFlags ,
1111} ;
1212use intern:: sym;
1313use rustc_type_ir:: {
@@ -276,10 +276,23 @@ impl<'db> ChalkToNextSolver<'db, Ty<'db>> for chalk_ir::Ty<Interner> {
276276 ) ,
277277 chalk_ir:: TyKind :: Error => rustc_type_ir:: TyKind :: Error ( ErrorGuaranteed ) ,
278278 chalk_ir:: TyKind :: Placeholder ( placeholder_index) => {
279- rustc_type_ir:: TyKind :: Placeholder ( PlaceholderTy :: new_anon (
280- placeholder_index. ui . to_nextsolver ( interner) ,
281- rustc_type_ir:: BoundVar :: from_usize ( placeholder_index. idx ) ,
282- ) )
279+ if placeholder_index. idx < 128 {
280+ dbg ! ( placeholder_index. idx) ;
281+ rustc_type_ir:: TyKind :: Placeholder ( PlaceholderTy :: new_anon (
282+ placeholder_index. ui . to_nextsolver ( interner) ,
283+ rustc_type_ir:: BoundVar :: from_usize ( placeholder_index. idx ) ,
284+ ) )
285+ } else {
286+ let id =
287+ crate :: mapping:: from_placeholder_idx ( interner. db , * placeholder_index) ;
288+ rustc_type_ir:: TyKind :: Placeholder ( PlaceholderTy :: new (
289+ placeholder_index. ui . to_nextsolver ( interner) ,
290+ BoundTy {
291+ var : BoundVar :: from_u32 ( id. local_id . into_raw ( ) . into_u32 ( ) ) ,
292+ kind : BoundTyKind :: Param ( id. parent . into ( ) ) ,
293+ } ,
294+ ) )
295+ }
283296 }
284297 chalk_ir:: TyKind :: Dyn ( dyn_ty) => {
285298 // exists<type> { for<...> ^1.0: ... }
@@ -559,8 +572,27 @@ impl<'db> ChalkToNextSolver<'db, Ty<'db>> for chalk_ir::Ty<Interner> {
559572
560573 rustc_type_ir:: TyKind :: Placeholder ( placeholder) => {
561574 let ui = chalk_ir:: UniverseIndex { counter : placeholder. universe . as_usize ( ) } ;
562- let placeholder_index =
563- chalk_ir:: PlaceholderIndex { idx : placeholder. bound . var . as_usize ( ) , ui } ;
575+ let placeholder_index = match placeholder. bound . kind {
576+ BoundTyKind :: Anon => {
577+ chalk_ir:: PlaceholderIndex { idx : placeholder. bound . var . as_usize ( ) , ui }
578+ }
579+ BoundTyKind :: Param ( solver_def_id) => {
580+ let Some ( def) =
581+ solver_def_id_to_generic_def_id_opt ( interner. db , solver_def_id)
582+ else {
583+ unreachable ! ( )
584+ } ;
585+ crate :: mapping:: to_placeholder_idx (
586+ interner. db ,
587+ TypeOrConstParamId {
588+ parent : def,
589+ local_id : crate :: Idx :: from_raw (
590+ placeholder. bound . var . as_u32 ( ) . into ( ) ,
591+ ) ,
592+ } ,
593+ )
594+ }
595+ } ;
564596 TyKind :: Placeholder ( placeholder_index)
565597 }
566598
@@ -1986,8 +2018,24 @@ pub(crate) fn convert_ty_for_result<'db>(interner: DbInterner<'db>, ty: Ty<'db>)
19862018
19872019 rustc_type_ir:: TyKind :: Placeholder ( placeholder) => {
19882020 let ui = chalk_ir:: UniverseIndex { counter : placeholder. universe . as_usize ( ) } ;
1989- let placeholder_index =
1990- chalk_ir:: PlaceholderIndex { idx : placeholder. bound . var . as_usize ( ) , ui } ;
2021+ let placeholder_index = match placeholder. bound . kind {
2022+ BoundTyKind :: Anon => {
2023+ chalk_ir:: PlaceholderIndex { idx : placeholder. bound . var . as_usize ( ) , ui }
2024+ }
2025+ BoundTyKind :: Param ( solver_def_id) => {
2026+ let Some ( def) = solver_def_id_to_generic_def_id_opt ( interner. db , solver_def_id)
2027+ else {
2028+ unreachable ! ( )
2029+ } ;
2030+ crate :: mapping:: to_placeholder_idx (
2031+ interner. db ,
2032+ TypeOrConstParamId {
2033+ parent : def,
2034+ local_id : crate :: Idx :: from_raw ( placeholder. bound . var . as_u32 ( ) . into ( ) ) ,
2035+ } ,
2036+ )
2037+ }
2038+ } ;
19912039 TyKind :: Placeholder ( placeholder_index)
19922040 }
19932041
@@ -2298,3 +2346,27 @@ impl InferenceVarExt for InferenceVar {
22982346 InferenceVar :: from ( vid. as_u32 ( ) )
22992347 }
23002348}
2349+
2350+ pub fn solver_def_id_to_generic_def_id_opt (
2351+ db : & dyn HirDatabase ,
2352+ id : SolverDefId ,
2353+ ) -> Option < GenericDefId > {
2354+ match id {
2355+ SolverDefId :: AdtId ( it) => Some ( it. into ( ) ) ,
2356+ SolverDefId :: ConstId ( it) => Some ( it. into ( ) ) ,
2357+ SolverDefId :: FunctionId ( it) => Some ( it. into ( ) ) ,
2358+ SolverDefId :: ImplId ( it) => Some ( it. into ( ) ) ,
2359+ SolverDefId :: StaticId ( it) => Some ( it. into ( ) ) ,
2360+ SolverDefId :: TraitId ( it) => Some ( it. into ( ) ) ,
2361+ SolverDefId :: TypeAliasId ( it) => Some ( it. into ( ) ) ,
2362+ SolverDefId :: Ctor ( crate :: next_solver:: Ctor :: Struct ( it) ) => Some ( it. into ( ) ) ,
2363+ SolverDefId :: Ctor ( crate :: next_solver:: Ctor :: Enum ( it) ) => Some ( it. loc ( db) . parent . into ( ) ) ,
2364+ SolverDefId :: InternedOpaqueTyId ( it) => match it. loc ( db) {
2365+ crate :: ImplTraitId :: ReturnTypeImplTrait ( it, _) => Some ( it. into ( ) ) ,
2366+ crate :: ImplTraitId :: TypeAliasImplTrait ( it, _) => Some ( it. into ( ) ) ,
2367+ crate :: ImplTraitId :: AsyncBlockTypeImplTrait ( ..) => None ,
2368+ } ,
2369+ SolverDefId :: InternedClosureId ( _) => None ,
2370+ SolverDefId :: InternedCoroutineId ( _) => None ,
2371+ }
2372+ }
0 commit comments