Rollup merge of #103984 - V0ldek:103974-refactor-mk_const, r=BoxyUwU
Refactor tcx mk_const parameters. Unroll the `ty::ConstS` parameter to `TyCtxt::mk_const` into separate `ty::ConstKind` and `Ty` parameters. Signature change is in:c97fd8183a/compiler/rustc_middle/src/ty/context.rs (L2234)
andc97fd8183a/compiler/rustc_middle/src/ty/context.rs (L2572-L2575)
the rest is callsites. Closes #103974 r? `@oli-obk`
This commit is contained in:
commit
b101f3a865
21 changed files with 74 additions and 104 deletions
|
@ -1655,13 +1655,10 @@ pub fn check_type_bounds<'tcx>(
|
||||||
GenericParamDefKind::Const { .. } => {
|
GenericParamDefKind::Const { .. } => {
|
||||||
let bound_var = ty::BoundVariableKind::Const;
|
let bound_var = ty::BoundVariableKind::Const;
|
||||||
bound_vars.push(bound_var);
|
bound_vars.push(bound_var);
|
||||||
tcx.mk_const(ty::ConstS {
|
tcx.mk_const(
|
||||||
ty: tcx.type_of(param.def_id),
|
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)),
|
||||||
kind: ty::ConstKind::Bound(
|
tcx.type_of(param.def_id),
|
||||||
ty::INNERMOST,
|
)
|
||||||
ty::BoundVar::from_usize(bound_vars.len() - 1),
|
|
||||||
),
|
|
||||||
})
|
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -773,10 +773,10 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
||||||
self.fold_const(bound_to)
|
self.fold_const(bound_to)
|
||||||
} else {
|
} else {
|
||||||
let var = self.canonical_var(info, const_var.into());
|
let var = self.canonical_var(info, const_var.into());
|
||||||
self.tcx().mk_const(ty::ConstS {
|
self.tcx().mk_const(
|
||||||
kind: ty::ConstKind::Bound(self.binder_index, var),
|
ty::ConstKind::Bound(self.binder_index, var),
|
||||||
ty: self.fold_ty(const_var.ty()),
|
self.fold_ty(const_var.ty()),
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,12 +147,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
|
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
|
||||||
let universe_mapped = universe_map(universe);
|
let universe_mapped = universe_map(universe);
|
||||||
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
|
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
|
||||||
self.tcx
|
self.tcx.mk_const(ty::ConstKind::Placeholder(placeholder_mapped), ty).into()
|
||||||
.mk_const(ty::ConstS {
|
|
||||||
kind: ty::ConstKind::Placeholder(placeholder_mapped),
|
|
||||||
ty,
|
|
||||||
})
|
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -741,10 +741,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||||
substs,
|
substs,
|
||||||
substs,
|
substs,
|
||||||
)?;
|
)?;
|
||||||
Ok(self.tcx().mk_const(ty::ConstS {
|
Ok(self.tcx().mk_const(
|
||||||
ty: c.ty(),
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
|
||||||
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
|
c.ty(),
|
||||||
}))
|
))
|
||||||
}
|
}
|
||||||
_ => relate::super_relate_consts(self, c, c),
|
_ => relate::super_relate_consts(self, c, c),
|
||||||
}
|
}
|
||||||
|
@ -955,10 +955,10 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
||||||
substs,
|
substs,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(self.tcx().mk_const(ty::ConstS {
|
Ok(self.tcx().mk_const(
|
||||||
ty: c.ty(),
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
|
||||||
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
|
c.ty(),
|
||||||
}))
|
))
|
||||||
}
|
}
|
||||||
_ => relate::super_relate_consts(self, c, c),
|
_ => relate::super_relate_consts(self, c, c),
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,13 +94,13 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
consts: &mut |bound_var: ty::BoundVar, ty| {
|
consts: &mut |bound_var: ty::BoundVar, ty| {
|
||||||
self.tcx.mk_const(ty::ConstS {
|
self.tcx.mk_const(
|
||||||
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
||||||
universe: next_universe,
|
universe: next_universe,
|
||||||
name: bound_var,
|
name: bound_var,
|
||||||
}),
|
}),
|
||||||
ty,
|
ty,
|
||||||
})
|
)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2065,13 +2065,13 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
|
||||||
if ty.has_non_region_param() || ty.has_non_region_infer() {
|
if ty.has_non_region_param() || ty.has_non_region_infer() {
|
||||||
bug!("const `{ct}`'s type should not reference params or types");
|
bug!("const `{ct}`'s type should not reference params or types");
|
||||||
}
|
}
|
||||||
tcx.mk_const(ty::ConstS {
|
tcx.mk_const(
|
||||||
ty,
|
ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
||||||
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
|
||||||
universe: ty::UniverseIndex::ROOT,
|
universe: ty::UniverseIndex::ROOT,
|
||||||
name: ty::BoundVar::from_usize(idx),
|
name: ty::BoundVar::from_usize(idx),
|
||||||
}),
|
}),
|
||||||
})
|
ty,
|
||||||
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
_ => arg,
|
_ => arg,
|
||||||
|
|
|
@ -341,10 +341,10 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|
||||||
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
|
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
|
||||||
}
|
}
|
||||||
GenericArgKind::Const(ct) => tcx
|
GenericArgKind::Const(ct) => tcx
|
||||||
.mk_const(ty::ConstS {
|
.mk_const(
|
||||||
ty: ct.ty(),
|
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
|
||||||
kind: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
|
ct.ty(),
|
||||||
})
|
)
|
||||||
.into(),
|
.into(),
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
|
@ -2414,10 +2414,8 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||||
let generics = tcx.generics_of(item_def_id.to_def_id());
|
let generics = tcx.generics_of(item_def_id.to_def_id());
|
||||||
let index = generics.param_def_id_to_index[&def_id];
|
let index = generics.param_def_id_to_index[&def_id];
|
||||||
let name = tcx.hir().name(hir_id);
|
let name = tcx.hir().name(hir_id);
|
||||||
let ty_const = tcx.mk_const(ty::ConstS {
|
let ty_const =
|
||||||
kind: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
|
tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty);
|
||||||
ty,
|
|
||||||
});
|
|
||||||
debug!(?ty_const);
|
debug!(?ty_const);
|
||||||
|
|
||||||
return Self::Ty(ty_const);
|
return Self::Ty(ty_const);
|
||||||
|
|
|
@ -310,7 +310,8 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
|
||||||
|
|
||||||
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Const<'tcx> {
|
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Const<'tcx> {
|
||||||
fn decode(decoder: &mut D) -> Self {
|
fn decode(decoder: &mut D) -> Self {
|
||||||
decoder.interner().mk_const(Decodable::decode(decoder))
|
let consts: ty::ConstS<'tcx> = Decodable::decode(decoder);
|
||||||
|
decoder.interner().mk_const(consts.kind, consts.ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,13 +77,13 @@ impl<'tcx> Const<'tcx> {
|
||||||
|
|
||||||
match Self::try_eval_lit_or_param(tcx, ty, expr) {
|
match Self::try_eval_lit_or_param(tcx, ty, expr) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => tcx.mk_const(ty::ConstS {
|
None => tcx.mk_const(
|
||||||
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst {
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst {
|
||||||
def: def.to_global(),
|
def: def.to_global(),
|
||||||
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
|
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
|
||||||
}),
|
}),
|
||||||
ty,
|
ty,
|
||||||
}),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,10 +138,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
let generics = tcx.generics_of(item_def_id.to_def_id());
|
let generics = tcx.generics_of(item_def_id.to_def_id());
|
||||||
let index = generics.param_def_id_to_index[&def_id];
|
let index = generics.param_def_id_to_index[&def_id];
|
||||||
let name = tcx.hir().name(hir_id);
|
let name = tcx.hir().name(hir_id);
|
||||||
Some(tcx.mk_const(ty::ConstS {
|
Some(tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty))
|
||||||
kind: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
|
|
||||||
ty,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
@ -150,7 +147,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
/// Interns the given value as a constant.
|
/// Interns the given value as a constant.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Self {
|
pub fn from_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Self {
|
||||||
tcx.mk_const(ConstS { kind: ConstKind::Value(val), ty })
|
tcx.mk_const(ConstKind::Value(val), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Panics if self.kind != ty::ConstKind::Value
|
/// Panics if self.kind != ty::ConstKind::Value
|
||||||
|
|
|
@ -1316,7 +1316,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> Const<'tcx> {
|
) -> Const<'tcx> {
|
||||||
let reported = self.sess.delay_span_bug(span, msg);
|
let reported = self.sess.delay_span_bug(span, msg);
|
||||||
self.mk_const(ty::ConstS { kind: ty::ConstKind::Error(reported), ty })
|
self.mk_const(ty::ConstKind::Error(reported), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
|
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
|
||||||
|
@ -2231,7 +2231,7 @@ macro_rules! direct_interners {
|
||||||
|
|
||||||
direct_interners! {
|
direct_interners! {
|
||||||
region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>,
|
region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>,
|
||||||
const_: mk_const(ConstS<'tcx>): Const -> Const<'tcx>,
|
const_: mk_const_internal(ConstS<'tcx>): Const -> Const<'tcx>,
|
||||||
const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
|
const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
|
||||||
layout: intern_layout(LayoutS<'tcx>): Layout -> Layout<'tcx>,
|
layout: intern_layout(LayoutS<'tcx>): Layout -> Layout<'tcx>,
|
||||||
adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>,
|
adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>,
|
||||||
|
@ -2569,9 +2569,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.mk_ty_infer(TyVar(v))
|
self.mk_ty_infer(TyVar(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn mk_const(self, kind: ty::ConstKind<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
self.mk_const_internal(ty::ConstS { kind, ty })
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
self.mk_const(ty::ConstS { kind: ty::ConstKind::Infer(InferConst::Var(v)), ty })
|
self.mk_const(ty::ConstKind::Infer(InferConst::Var(v)), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2591,7 +2596,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_const_infer(self, ic: InferConst<'tcx>, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
pub fn mk_const_infer(self, ic: InferConst<'tcx>, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
||||||
self.mk_const(ty::ConstS { kind: ty::ConstKind::Infer(ic), ty })
|
self.mk_const(ty::ConstKind::Infer(ic), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2601,7 +2606,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_const_param(self, index: u32, name: Symbol, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn mk_const_param(self, index: u32, name: Symbol, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
self.mk_const(ty::ConstS { kind: ty::ConstKind::Param(ParamConst { index, name }), ty })
|
self.mk_const(ty::ConstKind::Param(ParamConst { index, name }), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
|
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
|
||||||
|
|
|
@ -566,10 +566,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
consts: &mut |c, ty: Ty<'tcx>| {
|
consts: &mut |c, ty: Ty<'tcx>| {
|
||||||
self.mk_const(ty::ConstS {
|
self.mk_const(ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)), ty)
|
||||||
kind: ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)),
|
|
||||||
ty,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -648,7 +645,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let index = entry.index();
|
let index = entry.index();
|
||||||
let var = ty::BoundVar::from_usize(index);
|
let var = ty::BoundVar::from_usize(index);
|
||||||
let () = entry.or_insert_with(|| ty::BoundVariableKind::Const).expect_const();
|
let () = entry.or_insert_with(|| ty::BoundVariableKind::Const).expect_const();
|
||||||
self.tcx.mk_const(ty::ConstS { ty, kind: ty::ConstKind::Bound(ty::INNERMOST, var) })
|
self.tcx.mk_const(ty::ConstKind::Bound(ty::INNERMOST, var), ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,10 +729,7 @@ impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> {
|
||||||
ct
|
ct
|
||||||
} else {
|
} else {
|
||||||
let debruijn = debruijn.shifted_in(self.amount);
|
let debruijn = debruijn.shifted_in(self.amount);
|
||||||
self.tcx.mk_const(ty::ConstS {
|
self.tcx.mk_const(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty())
|
||||||
kind: ty::ConstKind::Bound(debruijn, bound_ct),
|
|
||||||
ty: ct.ty(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ct.super_fold_with(self)
|
ct.super_fold_with(self)
|
||||||
|
|
|
@ -639,10 +639,10 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
|
||||||
au.substs,
|
au.substs,
|
||||||
bu.substs,
|
bu.substs,
|
||||||
)?;
|
)?;
|
||||||
return Ok(tcx.mk_const(ty::ConstS {
|
return Ok(tcx.mk_const(
|
||||||
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def: au.def, substs }),
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def: au.def, substs }),
|
||||||
ty: a.ty(),
|
a.ty(),
|
||||||
}));
|
));
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -805,7 +805,7 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> {
|
||||||
let ty = self.ty().try_fold_with(folder)?;
|
let ty = self.ty().try_fold_with(folder)?;
|
||||||
let kind = self.kind().try_fold_with(folder)?;
|
let kind = self.kind().try_fold_with(folder)?;
|
||||||
if ty != self.ty() || kind != self.kind() {
|
if ty != self.ty() || kind != self.kind() {
|
||||||
Ok(folder.tcx().mk_const(ty::ConstS { ty, kind }))
|
Ok(folder.tcx().mk_const(kind, ty))
|
||||||
} else {
|
} else {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
Constant { user_ty, span, literal }
|
Constant { user_ty, span, literal }
|
||||||
}
|
}
|
||||||
ExprKind::ConstParam { param, def_id: _ } => {
|
ExprKind::ConstParam { param, def_id: _ } => {
|
||||||
let const_param =
|
let const_param = tcx.mk_const(ty::ConstKind::Param(param), expr.ty);
|
||||||
tcx.mk_const(ty::ConstS { kind: ty::ConstKind::Param(param), ty: expr.ty });
|
|
||||||
let literal = ConstantKind::Ty(const_param);
|
let literal = ConstantKind::Ty(const_param);
|
||||||
|
|
||||||
Constant { user_ty: None, span, literal }
|
Constant { user_ty: None, span, literal }
|
||||||
|
|
|
@ -654,8 +654,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||||
.builtin_deref(true)
|
.builtin_deref(true)
|
||||||
.expect("tried to dereference on non-ptr type")
|
.expect("tried to dereference on non-ptr type")
|
||||||
.ty;
|
.ty;
|
||||||
let dereferenced_const =
|
let dereferenced_const = self.tcx.mk_const(ct.kind(), pointee_ty);
|
||||||
self.tcx.mk_const(ty::ConstS { kind: ct.kind(), ty: pointee_ty });
|
|
||||||
self = dereferenced_const.print(self)?;
|
self = dereferenced_const.print(self)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -831,9 +831,7 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
|
||||||
let universe = self.universe_for(debruijn);
|
let universe = self.universe_for(debruijn);
|
||||||
let p = ty::PlaceholderConst { universe, name: bound_const };
|
let p = ty::PlaceholderConst { universe, name: bound_const };
|
||||||
self.mapped_consts.insert(p, bound_const);
|
self.mapped_consts.insert(p, bound_const);
|
||||||
self.infcx
|
self.infcx.tcx.mk_const(ty::ConstKind::Placeholder(p), ct.ty())
|
||||||
.tcx
|
|
||||||
.mk_const(ty::ConstS { kind: ty::ConstKind::Placeholder(p), ty: ct.ty() })
|
|
||||||
}
|
}
|
||||||
_ => ct.super_fold_with(self),
|
_ => ct.super_fold_with(self),
|
||||||
}
|
}
|
||||||
|
@ -968,10 +966,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> {
|
||||||
let db = ty::DebruijnIndex::from_usize(
|
let db = ty::DebruijnIndex::from_usize(
|
||||||
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
|
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
|
||||||
);
|
);
|
||||||
self.tcx().mk_const(ty::ConstS {
|
self.tcx().mk_const(ty::ConstKind::Bound(db, *replace_var), ct.ty())
|
||||||
kind: ty::ConstKind::Bound(db, *replace_var),
|
|
||||||
ty: ct.ty(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
None => ct,
|
None => ct,
|
||||||
}
|
}
|
||||||
|
@ -2173,7 +2168,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
||||||
crate::traits::InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
|
crate::traits::InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
|
||||||
let did = ty::WithOptConstParam::unknown(assoc_ty.item.def_id);
|
let did = ty::WithOptConstParam::unknown(assoc_ty.item.def_id);
|
||||||
let kind = ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(did, identity_substs));
|
let kind = ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(did, identity_substs));
|
||||||
ty.map_bound(|ty| tcx.mk_const(ty::ConstS { ty, kind }).into())
|
ty.map_bound(|ty| tcx.mk_const(kind, ty).into())
|
||||||
} else {
|
} else {
|
||||||
ty.map_bound(|ty| ty.into())
|
ty.map_bound(|ty| ty.into())
|
||||||
};
|
};
|
||||||
|
|
|
@ -555,13 +555,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
GenericParamDefKind::Const { .. } => {
|
GenericParamDefKind::Const { .. } => {
|
||||||
let bound_var = ty::BoundVariableKind::Const;
|
let bound_var = ty::BoundVariableKind::Const;
|
||||||
bound_vars.push(bound_var);
|
bound_vars.push(bound_var);
|
||||||
tcx.mk_const(ty::ConstS {
|
tcx.mk_const(
|
||||||
ty: tcx.type_of(param.def_id),
|
ty::ConstKind::Bound(
|
||||||
kind: ty::ConstKind::Bound(
|
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundVar::from_usize(bound_vars.len() - 1),
|
ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||||
),
|
),
|
||||||
})
|
tcx.type_of(param.def_id),
|
||||||
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -734,10 +734,10 @@ fn bound_vars_for_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::GenericParamDefKind::Const { .. } => tcx
|
ty::GenericParamDefKind::Const { .. } => tcx
|
||||||
.mk_const(ty::ConstS {
|
.mk_const(
|
||||||
kind: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
|
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
|
||||||
ty: tcx.type_of(param.def_id),
|
tcx.type_of(param.def_id),
|
||||||
})
|
)
|
||||||
.into(),
|
.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -546,7 +546,7 @@ impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const<RustInterner<'t
|
||||||
chalk_ir::ConstValue::Placeholder(_p) => unimplemented!(),
|
chalk_ir::ConstValue::Placeholder(_p) => unimplemented!(),
|
||||||
chalk_ir::ConstValue::Concrete(c) => ty::ConstKind::Value(c.interned),
|
chalk_ir::ConstValue::Concrete(c) => ty::ConstKind::Value(c.interned),
|
||||||
};
|
};
|
||||||
interner.tcx.mk_const(ty::ConstS { ty, kind })
|
interner.tcx.mk_const(kind, ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub(crate) fn destructure_const<'tcx>(
|
||||||
// construct the consts for the elements of the array/slice
|
// construct the consts for the elements of the array/slice
|
||||||
let field_consts = branches
|
let field_consts = branches
|
||||||
.iter()
|
.iter()
|
||||||
.map(|b| tcx.mk_const(ty::ConstS { kind: ty::ConstKind::Value(*b), ty: *inner_ty }))
|
.map(|b| tcx.mk_const(ty::ConstKind::Value(*b), *inner_ty))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
debug!(?field_consts);
|
debug!(?field_consts);
|
||||||
|
|
||||||
|
@ -52,10 +52,7 @@ pub(crate) fn destructure_const<'tcx>(
|
||||||
|
|
||||||
for (field, field_valtree) in iter::zip(fields, branches) {
|
for (field, field_valtree) in iter::zip(fields, branches) {
|
||||||
let field_ty = field.ty(tcx, substs);
|
let field_ty = field.ty(tcx, substs);
|
||||||
let field_const = tcx.mk_const(ty::ConstS {
|
let field_const = tcx.mk_const(ty::ConstKind::Value(*field_valtree), field_ty);
|
||||||
kind: ty::ConstKind::Value(*field_valtree),
|
|
||||||
ty: field_ty,
|
|
||||||
});
|
|
||||||
field_consts.push(field_const);
|
field_consts.push(field_const);
|
||||||
}
|
}
|
||||||
debug!(?field_consts);
|
debug!(?field_consts);
|
||||||
|
@ -65,10 +62,7 @@ pub(crate) fn destructure_const<'tcx>(
|
||||||
ty::Tuple(elem_tys) => {
|
ty::Tuple(elem_tys) => {
|
||||||
let fields = iter::zip(*elem_tys, branches)
|
let fields = iter::zip(*elem_tys, branches)
|
||||||
.map(|(elem_ty, elem_valtree)| {
|
.map(|(elem_ty, elem_valtree)| {
|
||||||
tcx.mk_const(ty::ConstS {
|
tcx.mk_const(ty::ConstKind::Value(*elem_valtree), elem_ty)
|
||||||
kind: ty::ConstKind::Value(*elem_valtree),
|
|
||||||
ty: elem_ty,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -261,17 +255,13 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
||||||
let uneval =
|
let uneval =
|
||||||
ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
|
ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
|
||||||
|
|
||||||
let constant = self
|
let constant = self.tcx.mk_const(ty::ConstKind::Unevaluated(uneval), node.ty);
|
||||||
.tcx
|
|
||||||
.mk_const(ty::ConstS { kind: ty::ConstKind::Unevaluated(uneval), ty: node.ty });
|
|
||||||
|
|
||||||
self.nodes.push(Node::Leaf(constant))
|
self.nodes.push(Node::Leaf(constant))
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprKind::ConstParam { param, .. } => {
|
ExprKind::ConstParam { param, .. } => {
|
||||||
let const_param = self
|
let const_param = self.tcx.mk_const(ty::ConstKind::Param(*param), node.ty);
|
||||||
.tcx
|
|
||||||
.mk_const(ty::ConstS { kind: ty::ConstKind::Param(*param), ty: node.ty });
|
|
||||||
self.nodes.push(Node::Leaf(const_param))
|
self.nodes.push(Node::Leaf(const_param))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue