Replace mk_const
with Const::new_x
methods
This commit is contained in:
parent
cd68ead9ec
commit
ddbc774e74
32 changed files with 219 additions and 134 deletions
|
@ -386,11 +386,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
.type_of(param.def_id)
|
.type_of(param.def_id)
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("ct params cannot have early bound vars");
|
.expect("ct params cannot have early bound vars");
|
||||||
tcx.mk_const(
|
ty::Const::new_bound(
|
||||||
ty::ConstKind::Bound(
|
tcx,
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundVar::from_usize(num_bound_vars),
|
ty::BoundVar::from_usize(num_bound_vars),
|
||||||
),
|
|
||||||
ty,
|
ty,
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
|
|
|
@ -1970,7 +1970,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
assert!(!ct.ty().has_escaping_bound_vars());
|
assert!(!ct.ty().has_escaping_bound_vars());
|
||||||
|
|
||||||
match ct.kind() {
|
match ct.kind() {
|
||||||
ty::ConstKind::Bound(_, bv) => self.tcx.mk_const(
|
ty::ConstKind::Bound(_, bv) => ty::Const::new_placeholder(
|
||||||
|
self.tcx,
|
||||||
ty::PlaceholderConst { universe: self.universe, bound: bv },
|
ty::PlaceholderConst { universe: self.universe, bound: bv },
|
||||||
ct.ty(),
|
ct.ty(),
|
||||||
),
|
),
|
||||||
|
|
|
@ -2047,11 +2047,10 @@ pub(super) 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::Const::new_bound(
|
||||||
ty::ConstKind::Bound(
|
tcx,
|
||||||
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)
|
tcx.type_of(param.def_id)
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("const parameter types cannot be generic"),
|
.expect("const parameter types cannot be generic"),
|
||||||
|
|
|
@ -243,9 +243,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
let name = param.name.ident().name;
|
let name = param.name.ident().name;
|
||||||
let param_const = ty::ParamConst::new(index, name);
|
let param_const = ty::ParamConst::new(index, name);
|
||||||
|
|
||||||
let ct_ty = tcx.type_of(param.def_id.to_def_id()).subst_identity();
|
let ct_ty = tcx
|
||||||
|
.type_of(param.def_id.to_def_id())
|
||||||
|
.no_bound_vars()
|
||||||
|
.expect("const parameters cannot be generic");
|
||||||
|
|
||||||
let ct = tcx.mk_const(param_const, ct_ty);
|
let ct = ty::Const::new_param(tcx, param_const, ct_ty);
|
||||||
|
|
||||||
predicates.insert((
|
predicates.insert((
|
||||||
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx),
|
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx),
|
||||||
|
|
|
@ -497,7 +497,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
|
||||||
// any equated inference vars correctly!
|
// any equated inference vars correctly!
|
||||||
let root_vid = self.infcx.root_const_var(vid);
|
let root_vid = self.infcx.root_const_var(vid);
|
||||||
if root_vid != vid {
|
if root_vid != vid {
|
||||||
ct = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), ct.ty());
|
ct = ty::Const::new_var(self.infcx.tcx, root_vid, ct.ty());
|
||||||
vid = root_vid;
|
vid = root_vid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -804,10 +804,7 @@ 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.interner().mk_const(
|
ty::Const::new_bound(self.tcx, self.binder_index, var, self.fold_ty(const_var.ty()))
|
||||||
ty::ConstKind::Bound(self.binder_index, var),
|
|
||||||
self.fold_ty(const_var.ty()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }, ty) => {
|
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }, ty) => {
|
||||||
let universe_mapped = universe_map(universe);
|
let universe_mapped = universe_map(universe);
|
||||||
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
|
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
|
||||||
self.tcx.mk_const(placeholder_mapped, ty).into()
|
ty::Const::new_placeholder(self.tcx, placeholder_mapped, ty).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
let index = self.const_freshen_count;
|
let index = self.const_freshen_count;
|
||||||
self.const_freshen_count += 1;
|
self.const_freshen_count += 1;
|
||||||
let ct = self.infcx.tcx.mk_const(freshener(index), ty);
|
let ct = ty::Const::new_infer(self.infcx.tcx, freshener(index), ty);
|
||||||
entry.insert(ct);
|
entry.insert(ct);
|
||||||
ct
|
ct
|
||||||
}
|
}
|
||||||
|
|
|
@ -398,7 +398,7 @@ where
|
||||||
origin: var_value.origin,
|
origin: var_value.origin,
|
||||||
val: ConstVariableValue::Unknown { universe: self.for_universe },
|
val: ConstVariableValue::Unknown { universe: self.for_universe },
|
||||||
});
|
});
|
||||||
Ok(self.tcx().mk_const(new_var_id, c.ty()))
|
Ok(ty::Const::new_var(self.tcx(), new_var_id, c.ty()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,11 @@ where
|
||||||
substs,
|
substs,
|
||||||
substs,
|
substs,
|
||||||
)?;
|
)?;
|
||||||
Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty()))
|
Ok(ty::Const::new_unevaluated(
|
||||||
|
self.tcx(),
|
||||||
|
ty::UnevaluatedConst { def, substs },
|
||||||
|
c.ty(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
ty::ConstKind::Placeholder(placeholder) => {
|
ty::ConstKind::Placeholder(placeholder) => {
|
||||||
if self.for_universe.can_name(placeholder.universe) {
|
if self.for_universe.can_name(placeholder.universe) {
|
||||||
|
|
|
@ -94,7 +94,8 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
consts: &mut |bound_var: ty::BoundVar, ty| {
|
consts: &mut |bound_var: ty::BoundVar, ty| {
|
||||||
self.tcx.mk_const(
|
ty::Const::new_placeholder(
|
||||||
|
self.tcx,
|
||||||
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
|
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
|
||||||
ty,
|
ty,
|
||||||
)
|
)
|
||||||
|
|
|
@ -999,7 +999,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
|
pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
|
||||||
self.tcx.mk_const(self.next_const_var_id(origin), ty)
|
ty::Const::new_var(self.tcx, self.next_const_var_id(origin), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_const_var_in_universe(
|
pub fn next_const_var_in_universe(
|
||||||
|
@ -1013,7 +1013,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.const_unification_table()
|
.const_unification_table()
|
||||||
.new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } });
|
.new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } });
|
||||||
self.tcx.mk_const(vid, ty)
|
ty::Const::new_var(self.tcx, vid, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid<'tcx> {
|
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid<'tcx> {
|
||||||
|
@ -1131,15 +1131,15 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
origin,
|
origin,
|
||||||
val: ConstVariableValue::Unknown { universe: self.universe() },
|
val: ConstVariableValue::Unknown { universe: self.universe() },
|
||||||
});
|
});
|
||||||
self.tcx
|
ty::Const::new_var(
|
||||||
.mk_const(
|
self.tcx,
|
||||||
const_var_id,
|
const_var_id,
|
||||||
self.tcx
|
self.tcx
|
||||||
.type_of(param.def_id)
|
.type_of(param.def_id)
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("const parameter types cannot be generic"),
|
.expect("const parameter types cannot be generic"),
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1472,7 +1472,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
) -> Result<ty::Const<'tcx>, ErrorHandled> {
|
) -> Result<ty::Const<'tcx>, ErrorHandled> {
|
||||||
match self.const_eval_resolve(param_env, unevaluated, span) {
|
match self.const_eval_resolve(param_env, unevaluated, span) {
|
||||||
Ok(Some(val)) => Ok(self.tcx.mk_const(val, ty)),
|
Ok(Some(val)) => Ok(ty::Const::new_value(self.tcx, val, ty)),
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let def_id = unevaluated.def;
|
let def_id = unevaluated.def;
|
||||||
|
@ -1964,7 +1964,8 @@ 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 `{c}`'s type should not reference params or types");
|
bug!("const `{c}`'s type should not reference params or types");
|
||||||
}
|
}
|
||||||
self.tcx.mk_const(
|
ty::Const::new_placeholder(
|
||||||
|
self.tcx,
|
||||||
ty::PlaceholderConst {
|
ty::PlaceholderConst {
|
||||||
universe: ty::UniverseIndex::ROOT,
|
universe: ty::UniverseIndex::ROOT,
|
||||||
bound: ty::BoundVar::from_u32({
|
bound: ty::BoundVar::from_u32({
|
||||||
|
|
|
@ -443,12 +443,13 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|
||||||
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
|
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
|
||||||
}
|
}
|
||||||
CanonicalVarKind::Const(_, ty)
|
CanonicalVarKind::Const(_, ty)
|
||||||
| CanonicalVarKind::PlaceholderConst(_, ty) => tcx
|
| CanonicalVarKind::PlaceholderConst(_, ty) => ty::Const::new_bound(
|
||||||
.mk_const(
|
tcx,
|
||||||
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(i)),
|
ty::INNERMOST,
|
||||||
ty,
|
ty::BoundVar::from_usize(i),
|
||||||
)
|
ty,
|
||||||
.into(),
|
)
|
||||||
|
.into(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -2510,7 +2510,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||||
let generics = tcx.generics_of(item_def_id);
|
let generics = tcx.generics_of(item_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.item_name(def_id);
|
let name = tcx.item_name(def_id);
|
||||||
let ty_const = tcx.mk_const(ty::ParamConst::new(index, name), ty);
|
let ty_const = ty::Const::new_param(tcx, ty::ParamConst::new(index, name), ty);
|
||||||
debug!(?ty_const);
|
debug!(?ty_const);
|
||||||
|
|
||||||
return Self::Ty(ty_const);
|
return Self::Ty(ty_const);
|
||||||
|
|
|
@ -344,7 +344,7 @@ 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 {
|
||||||
let consts: ty::ConstData<'tcx> = Decodable::decode(decoder);
|
let consts: ty::ConstData<'tcx> = Decodable::decode(decoder);
|
||||||
decoder.interner().mk_const(consts.kind, consts.ty)
|
decoder.interner().mk_ct_from_kind(consts.kind, consts.ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,69 @@ impl<'tcx> Const<'tcx> {
|
||||||
self.0.kind
|
self.0.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new(tcx: TyCtxt<'tcx>, kind: ty::ConstKind<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
tcx.mk_ct_from_kind(kind, ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_param(tcx: TyCtxt<'tcx>, param: ty::ParamConst, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Param(param), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_var(tcx: TyCtxt<'tcx>, infer: ty::ConstVid<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Infer(ty::InferConst::Var(infer)), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_fresh(tcx: TyCtxt<'tcx>, fresh: u32, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Infer(ty::InferConst::Fresh(fresh)), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Infer(infer), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_bound(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
debruijn: ty::DebruijnIndex,
|
||||||
|
var: ty::BoundVar,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
|
) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Bound(debruijn, var), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_placeholder(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
placeholder: ty::PlaceholderConst<'tcx>,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
|
) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Placeholder(placeholder), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_unevaluated(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
uv: ty::UnevaluatedConst<'tcx>,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
|
) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Unevaluated(uv), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Value(val), ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_expr(tcx: TyCtxt<'tcx>, expr: ty::Expr<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
Const::new(tcx, ty::ConstKind::Expr(expr), ty)
|
||||||
|
}
|
||||||
|
|
||||||
/// Literals and const generic parameters are eagerly converted to a constant, everything else
|
/// Literals and const generic parameters are eagerly converted to a constant, everything else
|
||||||
/// becomes `Unevaluated`.
|
/// becomes `Unevaluated`.
|
||||||
#[instrument(skip(tcx), level = "debug")]
|
#[instrument(skip(tcx), level = "debug")]
|
||||||
|
@ -60,7 +123,8 @@ 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(
|
None => ty::Const::new_unevaluated(
|
||||||
|
tcx,
|
||||||
ty::UnevaluatedConst {
|
ty::UnevaluatedConst {
|
||||||
def: def.to_def_id(),
|
def: def.to_def_id(),
|
||||||
substs: InternalSubsts::identity_for_item(tcx, def.to_def_id()),
|
substs: InternalSubsts::identity_for_item(tcx, def.to_def_id()),
|
||||||
|
@ -126,12 +190,16 @@ impl<'tcx> Const<'tcx> {
|
||||||
let generics = tcx.generics_of(item_def_id);
|
let generics = tcx.generics_of(item_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.item_name(def_id);
|
let name = tcx.item_name(def_id);
|
||||||
Some(tcx.mk_const(ty::ParamConst::new(index, name), param_ty))
|
Some(ty::Const::new_param(tcx, ty::ParamConst::new(index, name), param_ty))
|
||||||
|
}
|
||||||
|
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => {
|
||||||
|
Some(ty::Const::new_bound(
|
||||||
|
tcx,
|
||||||
|
debruijn,
|
||||||
|
ty::BoundVar::from_u32(index),
|
||||||
|
param_ty,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => Some(tcx.mk_const(
|
|
||||||
ty::ConstKind::Bound(debruijn, ty::BoundVar::from_u32(index)),
|
|
||||||
param_ty,
|
|
||||||
)),
|
|
||||||
Some(rbv::ResolvedArg::Error(guar)) => Some(tcx.const_error(param_ty, guar)),
|
Some(rbv::ResolvedArg::Error(guar)) => Some(tcx.const_error(param_ty, guar)),
|
||||||
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id),
|
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id),
|
||||||
}
|
}
|
||||||
|
@ -155,7 +223,8 @@ impl<'tcx> Const<'tcx> {
|
||||||
.layout_of(ty)
|
.layout_of(ty)
|
||||||
.unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e))
|
.unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e))
|
||||||
.size;
|
.size;
|
||||||
tcx.mk_const(
|
ty::Const::new_value(
|
||||||
|
tcx,
|
||||||
ty::ValTree::from_scalar_int(ScalarInt::try_from_uint(bits, size).unwrap()),
|
ty::ValTree::from_scalar_int(ScalarInt::try_from_uint(bits, size).unwrap()),
|
||||||
ty.value,
|
ty.value,
|
||||||
)
|
)
|
||||||
|
@ -164,7 +233,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Creates an interned zst constant.
|
/// Creates an interned zst constant.
|
||||||
pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
|
pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
|
||||||
tcx.mk_const(ty::ValTree::zst(), ty)
|
ty::Const::new_value(tcx, ty::ValTree::zst(), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -215,7 +284,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> {
|
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> {
|
||||||
if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) {
|
if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) {
|
||||||
match val {
|
match val {
|
||||||
Ok(val) => tcx.mk_const(val, self.ty()),
|
Ok(val) => ty::Const::new_value(tcx, val, self.ty()),
|
||||||
Err(guar) => tcx.const_error(self.ty(), guar),
|
Err(guar) => tcx.const_error(self.ty(), guar),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -736,7 +736,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn const_error(self, ty: Ty<'tcx>, reported: ErrorGuaranteed) -> Const<'tcx> {
|
pub fn const_error(self, ty: Ty<'tcx>, reported: ErrorGuaranteed) -> Const<'tcx> {
|
||||||
self.mk_const(ty::ConstKind::Error(reported), ty)
|
self.mk_ct_from_kind(ty::ConstKind::Error(reported), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like [TyCtxt::ty_error] but for constants.
|
/// Like [TyCtxt::ty_error] but for constants.
|
||||||
|
@ -758,7 +758,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
msg: &'static str,
|
msg: &'static 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::ConstKind::Error(reported), ty)
|
self.const_error(ty, reported)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
|
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
|
||||||
|
@ -1924,8 +1924,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_const(self, kind: impl Into<ty::ConstKind<'tcx>>, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn mk_ct_from_kind(self, kind: ty::ConstKind<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
self.intern_const(ty::ConstData { kind: kind.into(), ty })
|
self.intern_const(ty::ConstData { kind, ty })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1989,14 +1989,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
ty::Region::new_early_bound(self, param.to_early_bound_region_data()).into()
|
ty::Region::new_early_bound(self, param.to_early_bound_region_data()).into()
|
||||||
}
|
}
|
||||||
GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(),
|
GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(),
|
||||||
GenericParamDefKind::Const { .. } => self
|
GenericParamDefKind::Const { .. } => ty::Const::new_param(
|
||||||
.mk_const(
|
self,
|
||||||
ParamConst { index: param.index, name: param.name },
|
ParamConst { index: param.index, name: param.name },
|
||||||
self.type_of(param.def_id)
|
self.type_of(param.def_id)
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("const parameter types cannot be generic"),
|
.expect("const parameter types cannot be generic"),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.mk_bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind })
|
self.mk_bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind })
|
||||||
},
|
},
|
||||||
consts: &mut |c, ty: Ty<'tcx>| {
|
consts: &mut |c, ty: Ty<'tcx>| {
|
||||||
self.mk_const(ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)), ty)
|
ty::Const::new_bound(self, ty::INNERMOST, shift_bv(c), ty)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -400,7 +400,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::ConstKind::Bound(ty::INNERMOST, var), ty)
|
ty::Const::new_bound(self.tcx, ty::INNERMOST, var, ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +475,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Shifter<'tcx> {
|
||||||
&& debruijn >= self.current_index
|
&& debruijn >= self.current_index
|
||||||
{
|
{
|
||||||
let debruijn = debruijn.shifted_in(self.amount);
|
let debruijn = debruijn.shifted_in(self.amount);
|
||||||
self.tcx.mk_const(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty())
|
ty::Const::new_bound(self.tcx, debruijn, bound_ct, ct.ty())
|
||||||
} else {
|
} else {
|
||||||
ct.super_fold_with(self)
|
ct.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::error::UnsupportedFnAbi;
|
||||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||||
use crate::query::TyCtxtAt;
|
use crate::query::TyCtxtAt;
|
||||||
use crate::ty::normalize_erasing_regions::NormalizationError;
|
use crate::ty::normalize_erasing_regions::NormalizationError;
|
||||||
use crate::ty::{self, ReprOptions, Ty, TyCtxt, TypeVisitableExt};
|
use crate::ty::{self, ConstKind, ReprOptions, Ty, TyCtxt, TypeVisitableExt};
|
||||||
use rustc_error_messages::DiagnosticMessage;
|
use rustc_error_messages::DiagnosticMessage;
|
||||||
use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
|
use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -480,13 +480,11 @@ fn mul_sorted_consts<'tcx>(
|
||||||
b: ty::Const<'tcx>,
|
b: ty::Const<'tcx>,
|
||||||
) -> Option<ty::Const<'tcx>> {
|
) -> Option<ty::Const<'tcx>> {
|
||||||
use crate::mir::BinOp::Mul;
|
use crate::mir::BinOp::Mul;
|
||||||
use ty::ConstKind::Expr;
|
|
||||||
use ty::Expr::Binop;
|
|
||||||
|
|
||||||
let mut work = vec![a, b];
|
let mut work = vec![a, b];
|
||||||
let mut done = vec![];
|
let mut done = vec![];
|
||||||
while let Some(n) = work.pop() {
|
while let Some(n) = work.pop() {
|
||||||
if let Expr(Binop(Mul, l, r)) = n.kind() {
|
if let ConstKind::Expr(ty::Expr::Binop(Mul, l, r)) = n.kind() {
|
||||||
work.push(l);
|
work.push(l);
|
||||||
work.push(r)
|
work.push(r)
|
||||||
} else {
|
} else {
|
||||||
|
@ -517,7 +515,7 @@ fn mul_sorted_consts<'tcx>(
|
||||||
done.sort_unstable();
|
done.sort_unstable();
|
||||||
|
|
||||||
// create a single tree from the buffer
|
// create a single tree from the buffer
|
||||||
done.into_iter().reduce(|acc, n| tcx.mk_const(Expr(Binop(Mul, n, acc)), n.ty()))
|
done.into_iter().reduce(|acc, n| ty::Const::new_expr(tcx, ty::Expr::Binop(Mul, n, acc), n.ty()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasTyCtxt<'tcx>: HasDataLayout {
|
pub trait HasTyCtxt<'tcx>: HasDataLayout {
|
||||||
|
|
|
@ -1601,7 +1601,8 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
}
|
}
|
||||||
// Aggregates, printed as array/tuple/struct/variant construction syntax.
|
// Aggregates, printed as array/tuple/struct/variant construction syntax.
|
||||||
(ty::ValTree::Branch(_), ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) => {
|
(ty::ValTree::Branch(_), ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) => {
|
||||||
let contents = self.tcx().destructure_const(self.tcx().mk_const(valtree, ty));
|
let contents =
|
||||||
|
self.tcx().destructure_const(ty::Const::new_value(self.tcx(), valtree, ty));
|
||||||
let fields = contents.fields.iter().copied();
|
let fields = contents.fields.iter().copied();
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Array(..) => {
|
ty::Array(..) => {
|
||||||
|
|
|
@ -627,7 +627,11 @@ pub fn structurally_relate_consts<'tcx, R: TypeRelation<'tcx>>(
|
||||||
au.substs,
|
au.substs,
|
||||||
bu.substs,
|
bu.substs,
|
||||||
)?;
|
)?;
|
||||||
return Ok(tcx.mk_const(ty::UnevaluatedConst { def: au.def, substs }, a.ty()));
|
return Ok(ty::Const::new_unevaluated(
|
||||||
|
tcx,
|
||||||
|
ty::UnevaluatedConst { def: au.def, substs },
|
||||||
|
a.ty(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
// Before calling relate on exprs, it is necessary to ensure that the nested consts
|
// Before calling relate on exprs, it is necessary to ensure that the nested consts
|
||||||
// have identical types.
|
// have identical types.
|
||||||
|
@ -668,8 +672,7 @@ pub fn structurally_relate_consts<'tcx, R: TypeRelation<'tcx>>(
|
||||||
}
|
}
|
||||||
_ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))),
|
_ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))),
|
||||||
};
|
};
|
||||||
let kind = ty::ConstKind::Expr(expr);
|
return Ok(ty::Const::new_expr(tcx, expr, a.ty()));
|
||||||
return Ok(tcx.mk_const(kind, a.ty()));
|
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -730,7 +730,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'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.interner().mk_const(kind, ty))
|
Ok(folder.interner().mk_ct_from_kind(kind, ty))
|
||||||
} else {
|
} else {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub fn as_constant_inner<'tcx>(
|
||||||
Constant { user_ty, span, literal }
|
Constant { user_ty, span, literal }
|
||||||
}
|
}
|
||||||
ExprKind::ConstParam { param, def_id: _ } => {
|
ExprKind::ConstParam { param, def_id: _ } => {
|
||||||
let const_param = tcx.mk_const(ty::ConstKind::Param(param), expr.ty);
|
let const_param = ty::Const::new_param(tcx, param, 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 }
|
||||||
|
|
|
@ -79,5 +79,5 @@ pub(crate) fn lit_to_const<'tcx>(
|
||||||
_ => return Err(LitToConstError::TypeError),
|
_ => return Err(LitToConstError::TypeError),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(tcx.mk_const(valtree, ty))
|
Ok(ty::Const::new_value(tcx, valtree, ty))
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,7 +380,9 @@ impl<'tcx> ConstToPat<'tcx> {
|
||||||
ty::Ref(_, pointee_ty, ..) => match *pointee_ty.kind() {
|
ty::Ref(_, pointee_ty, ..) => match *pointee_ty.kind() {
|
||||||
// `&str` is represented as a valtree, let's keep using this
|
// `&str` is represented as a valtree, let's keep using this
|
||||||
// optimization for now.
|
// optimization for now.
|
||||||
ty::Str => PatKind::Constant { value: mir::ConstantKind::Ty(tcx.mk_const(cv, ty)) },
|
ty::Str => PatKind::Constant {
|
||||||
|
value: mir::ConstantKind::Ty(ty::Const::new_value(tcx, cv, ty)),
|
||||||
|
},
|
||||||
// Backwards compatibility hack: support references to non-structural types,
|
// Backwards compatibility hack: support references to non-structural types,
|
||||||
// but hard error if we aren't behind a double reference. We could just use
|
// but hard error if we aren't behind a double reference. We could just use
|
||||||
// the fallback code path below, but that would allow *more* of this fishy
|
// the fallback code path below, but that would allow *more* of this fishy
|
||||||
|
@ -438,9 +440,9 @@ impl<'tcx> ConstToPat<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::FnDef(..) => {
|
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::FnDef(..) => PatKind::Constant {
|
||||||
PatKind::Constant { value: mir::ConstantKind::Ty(tcx.mk_const(cv, ty)) }
|
value: mir::ConstantKind::Ty(ty::Const::new_value(tcx, cv, ty)),
|
||||||
}
|
},
|
||||||
ty::FnPtr(..) | ty::RawPtr(..) => unreachable!(),
|
ty::FnPtr(..) | ty::RawPtr(..) => unreachable!(),
|
||||||
_ => {
|
_ => {
|
||||||
self.saw_const_match_error.set(true);
|
self.saw_const_match_error.set(true);
|
||||||
|
|
|
@ -525,7 +525,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
.tcx
|
.tcx
|
||||||
.const_eval_global_id_for_typeck(param_env_reveal_all, cid, Some(span))
|
.const_eval_global_id_for_typeck(param_env_reveal_all, cid, Some(span))
|
||||||
.map(|val| match val {
|
.map(|val| match val {
|
||||||
Some(valtree) => mir::ConstantKind::Ty(self.tcx.mk_const(valtree, ty)),
|
Some(valtree) => mir::ConstantKind::Ty(ty::Const::new_value(self.tcx, valtree, ty)),
|
||||||
None => mir::ConstantKind::Val(
|
None => mir::ConstantKind::Val(
|
||||||
self.tcx
|
self.tcx
|
||||||
.const_eval_global_id(param_env_reveal_all, cid, Some(span))
|
.const_eval_global_id(param_env_reveal_all, cid, Some(span))
|
||||||
|
@ -631,7 +631,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
if let Ok(Some(valtree)) =
|
if let Ok(Some(valtree)) =
|
||||||
self.tcx.const_eval_resolve_for_typeck(self.param_env, ct, Some(span))
|
self.tcx.const_eval_resolve_for_typeck(self.param_env, ct, Some(span))
|
||||||
{
|
{
|
||||||
self.const_to_pat(ConstantKind::Ty(self.tcx.mk_const(valtree, ty)), id, span, None).kind
|
self.const_to_pat(
|
||||||
|
ConstantKind::Ty(ty::Const::new_value(self.tcx, valtree, ty)),
|
||||||
|
id,
|
||||||
|
span,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.kind
|
||||||
} else {
|
} else {
|
||||||
// If that fails, convert it to an opaque constant pattern.
|
// If that fails, convert it to an opaque constant pattern.
|
||||||
match tcx.const_eval_resolve(self.param_env, uneval, None) {
|
match tcx.const_eval_resolve(self.param_env, uneval, None) {
|
||||||
|
|
|
@ -651,7 +651,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 = self.tcx.mk_const(ct.kind(), pointee_ty);
|
let dereferenced_const = self.tcx.mk_ct_from_kind(ct.kind(), pointee_ty);
|
||||||
self = dereferenced_const.print(self)?;
|
self = dereferenced_const.print(self)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -377,7 +377,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
|
||||||
// any equated inference vars correctly!
|
// any equated inference vars correctly!
|
||||||
let root_vid = self.infcx.root_const_var(vid);
|
let root_vid = self.infcx.root_const_var(vid);
|
||||||
if root_vid != vid {
|
if root_vid != vid {
|
||||||
c = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), c.ty());
|
c = ty::Const::new_var(self.infcx.tcx, root_vid, c.ty());
|
||||||
vid = root_vid;
|
vid = root_vid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,6 +426,6 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
|
||||||
var
|
var
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
self.interner().mk_const(ty::ConstKind::Bound(self.binder_index, var), c.ty())
|
ty::Const::new_bound(self.infcx.tcx, self.binder_index, var, c.ty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
||||||
let recursion_limit = tcx.recursion_limit();
|
let recursion_limit = tcx.recursion_limit();
|
||||||
if !recursion_limit.value_within_limit(self.depth) {
|
if !recursion_limit.value_within_limit(self.depth) {
|
||||||
self.at.infcx.err_ctxt().report_overflow_error(
|
self.at.infcx.err_ctxt().report_overflow_error(
|
||||||
&tcx.mk_const(uv, ty),
|
&ty::Const::new_unevaluated(tcx, uv, ty),
|
||||||
self.at.cause.span,
|
self.at.cause.span,
|
||||||
true,
|
true,
|
||||||
|_| {},
|
|_| {},
|
||||||
|
@ -131,7 +131,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
||||||
let ct = infcx.resolve_vars_if_possible(new_infer_ct);
|
let ct = infcx.resolve_vars_if_possible(new_infer_ct);
|
||||||
ct.try_fold_with(self)?
|
ct.try_fold_with(self)?
|
||||||
} else {
|
} else {
|
||||||
tcx.mk_const(uv, ty).try_super_fold_with(self)?
|
ty::Const::new_unevaluated(tcx, uv, ty).try_super_fold_with(self)?
|
||||||
};
|
};
|
||||||
|
|
||||||
self.depth -= 1;
|
self.depth -= 1;
|
||||||
|
|
|
@ -794,7 +794,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
||||||
unevaluated,
|
unevaluated,
|
||||||
Some(obligation.cause.span),
|
Some(obligation.cause.span),
|
||||||
) {
|
) {
|
||||||
Ok(Some(valtree)) => Ok(selcx.tcx().mk_const(valtree, c.ty())),
|
Ok(Some(valtree)) => Ok(ty::Const::new_value(selcx.tcx(),valtree, c.ty())),
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let reported =
|
let reported =
|
||||||
|
|
|
@ -1612,16 +1612,15 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
.tcx
|
.tcx
|
||||||
.mk_projection(data.projection_ty.def_id, data.projection_ty.substs)
|
.mk_projection(data.projection_ty.def_id, data.projection_ty.substs)
|
||||||
.into(),
|
.into(),
|
||||||
ty::TermKind::Const(ct) => self
|
ty::TermKind::Const(ct) => ty::Const::new_unevaluated(
|
||||||
.tcx
|
self.tcx,
|
||||||
.mk_const(
|
ty::UnevaluatedConst {
|
||||||
ty::UnevaluatedConst {
|
def: data.projection_ty.def_id,
|
||||||
def: data.projection_ty.def_id,
|
substs: data.projection_ty.substs,
|
||||||
substs: data.projection_ty.substs,
|
},
|
||||||
},
|
ct.ty(),
|
||||||
ct.ty(),
|
)
|
||||||
)
|
.into(),
|
||||||
.into(),
|
|
||||||
};
|
};
|
||||||
let normalized_term =
|
let normalized_term =
|
||||||
ocx.normalize(&obligation.cause, obligation.param_env, unnormalized_term);
|
ocx.normalize(&obligation.cause, obligation.param_env, unnormalized_term);
|
||||||
|
|
|
@ -924,7 +924,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarReplacer<'_, 'tcx> {
|
||||||
let universe = self.universe_for(debruijn);
|
let universe = self.universe_for(debruijn);
|
||||||
let p = ty::PlaceholderConst { universe, bound: bound_const };
|
let p = ty::PlaceholderConst { universe, bound: bound_const };
|
||||||
self.mapped_consts.insert(p, bound_const);
|
self.mapped_consts.insert(p, bound_const);
|
||||||
self.infcx.tcx.mk_const(p, ct.ty())
|
ty::Const::new_placeholder(self.infcx.tcx, p, ct.ty())
|
||||||
}
|
}
|
||||||
_ => ct.super_fold_with(self),
|
_ => ct.super_fold_with(self),
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1059,7 @@ impl<'tcx> TypeFolder<TyCtxt<'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.interner().mk_const(ty::ConstKind::Bound(db, *replace_var), ct.ty())
|
ty::Const::new_bound(self.infcx.tcx, db, *replace_var, ct.ty())
|
||||||
}
|
}
|
||||||
None => ct,
|
None => ct,
|
||||||
}
|
}
|
||||||
|
@ -1500,16 +1500,16 @@ fn project<'cx, 'tcx>(
|
||||||
DefKind::AssocTy | DefKind::ImplTraitPlaceholder => tcx
|
DefKind::AssocTy | DefKind::ImplTraitPlaceholder => tcx
|
||||||
.mk_projection(obligation.predicate.def_id, obligation.predicate.substs)
|
.mk_projection(obligation.predicate.def_id, obligation.predicate.substs)
|
||||||
.into(),
|
.into(),
|
||||||
DefKind::AssocConst => tcx
|
DefKind::AssocConst => ty::Const::new_unevaluated(
|
||||||
.mk_const(
|
tcx,
|
||||||
ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(
|
ty::UnevaluatedConst::new(
|
||||||
obligation.predicate.def_id,
|
obligation.predicate.def_id,
|
||||||
obligation.predicate.substs,
|
obligation.predicate.substs,
|
||||||
)),
|
),
|
||||||
tcx.type_of(obligation.predicate.def_id)
|
tcx.type_of(obligation.predicate.def_id)
|
||||||
.subst(tcx, obligation.predicate.substs),
|
.subst(tcx, obligation.predicate.substs),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
kind => {
|
kind => {
|
||||||
bug!("unknown projection def-id: {}", kind.descr(obligation.predicate.def_id))
|
bug!("unknown projection def-id: {}", kind.descr(obligation.predicate.def_id))
|
||||||
}
|
}
|
||||||
|
@ -2397,8 +2397,8 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
||||||
let term: ty::EarlyBinder<ty::Term<'tcx>> = if is_const {
|
let term: ty::EarlyBinder<ty::Term<'tcx>> = if is_const {
|
||||||
let did = assoc_ty.item.def_id;
|
let did = assoc_ty.item.def_id;
|
||||||
let identity_substs = crate::traits::InternalSubsts::identity_for_item(tcx, did);
|
let identity_substs = crate::traits::InternalSubsts::identity_for_item(tcx, did);
|
||||||
let kind = ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(did, identity_substs));
|
let uv = ty::UnevaluatedConst::new(did, identity_substs);
|
||||||
ty.map_bound(|ty| tcx.mk_const(kind, ty).into())
|
ty.map_bound(|ty| ty::Const::new_unevaluated(tcx, uv, ty).into())
|
||||||
} else {
|
} else {
|
||||||
ty.map_bound(|ty| ty.into())
|
ty.map_bound(|ty| ty.into())
|
||||||
};
|
};
|
||||||
|
|
|
@ -613,11 +613,10 @@ 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::Const::new_bound(
|
||||||
ty::ConstKind::Bound(
|
tcx,
|
||||||
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)
|
tcx.type_of(param.def_id)
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("const parameter types cannot be generic"),
|
.expect("const parameter types cannot be generic"),
|
||||||
|
|
|
@ -33,8 +33,10 @@ pub(crate) fn destructure_const<'tcx>(
|
||||||
let (fields, variant) = match const_.ty().kind() {
|
let (fields, variant) = match const_.ty().kind() {
|
||||||
ty::Array(inner_ty, _) | ty::Slice(inner_ty) => {
|
ty::Array(inner_ty, _) | ty::Slice(inner_ty) => {
|
||||||
// construct the consts for the elements of the array/slice
|
// construct the consts for the elements of the array/slice
|
||||||
let field_consts =
|
let field_consts = branches
|
||||||
branches.iter().map(|b| tcx.mk_const(*b, *inner_ty)).collect::<Vec<_>>();
|
.iter()
|
||||||
|
.map(|b| ty::Const::new_value(tcx, *b, *inner_ty))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
debug!(?field_consts);
|
debug!(?field_consts);
|
||||||
|
|
||||||
(field_consts, None)
|
(field_consts, None)
|
||||||
|
@ -52,7 +54,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(*field_valtree, field_ty);
|
let field_const = ty::Const::new_value(tcx, *field_valtree, field_ty);
|
||||||
field_consts.push(field_const);
|
field_consts.push(field_const);
|
||||||
}
|
}
|
||||||
debug!(?field_consts);
|
debug!(?field_consts);
|
||||||
|
@ -61,7 +63,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)| tcx.mk_const(*elem_valtree, elem_ty))
|
.map(|(elem_ty, elem_valtree)| ty::Const::new_value(tcx, *elem_valtree, elem_ty))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
(fields, None)
|
(fields, None)
|
||||||
|
@ -125,17 +127,17 @@ fn recurse_build<'tcx>(
|
||||||
}
|
}
|
||||||
&ExprKind::NonHirLiteral { lit, user_ty: _ } => {
|
&ExprKind::NonHirLiteral { lit, user_ty: _ } => {
|
||||||
let val = ty::ValTree::from_scalar_int(lit);
|
let val = ty::ValTree::from_scalar_int(lit);
|
||||||
tcx.mk_const(val, node.ty)
|
ty::Const::new_value(tcx, val, node.ty)
|
||||||
}
|
}
|
||||||
&ExprKind::ZstLiteral { user_ty: _ } => {
|
&ExprKind::ZstLiteral { user_ty: _ } => {
|
||||||
let val = ty::ValTree::zst();
|
let val = ty::ValTree::zst();
|
||||||
tcx.mk_const(val, node.ty)
|
ty::Const::new_value(tcx, val, node.ty)
|
||||||
}
|
}
|
||||||
&ExprKind::NamedConst { def_id, substs, user_ty: _ } => {
|
&ExprKind::NamedConst { def_id, substs, user_ty: _ } => {
|
||||||
let uneval = ty::UnevaluatedConst::new(def_id, substs);
|
let uneval = ty::UnevaluatedConst::new(def_id, substs);
|
||||||
tcx.mk_const(uneval, node.ty)
|
ty::Const::new_unevaluated(tcx, uneval, node.ty)
|
||||||
}
|
}
|
||||||
ExprKind::ConstParam { param, .. } => tcx.mk_const(*param, node.ty),
|
ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param, node.ty),
|
||||||
|
|
||||||
ExprKind::Call { fun, args, .. } => {
|
ExprKind::Call { fun, args, .. } => {
|
||||||
let fun = recurse_build(tcx, body, *fun, root_span)?;
|
let fun = recurse_build(tcx, body, *fun, root_span)?;
|
||||||
|
@ -145,16 +147,16 @@ fn recurse_build<'tcx>(
|
||||||
new_args.push(recurse_build(tcx, body, id, root_span)?);
|
new_args.push(recurse_build(tcx, body, id, root_span)?);
|
||||||
}
|
}
|
||||||
let new_args = tcx.mk_const_list(&new_args);
|
let new_args = tcx.mk_const_list(&new_args);
|
||||||
tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty)
|
ty::Const::new_expr(tcx, Expr::FunctionCall(fun, new_args), node.ty)
|
||||||
}
|
}
|
||||||
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {
|
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {
|
||||||
let lhs = recurse_build(tcx, body, lhs, root_span)?;
|
let lhs = recurse_build(tcx, body, lhs, root_span)?;
|
||||||
let rhs = recurse_build(tcx, body, rhs, root_span)?;
|
let rhs = recurse_build(tcx, body, rhs, root_span)?;
|
||||||
tcx.mk_const(Expr::Binop(op, lhs, rhs), node.ty)
|
ty::Const::new_expr(tcx, Expr::Binop(op, lhs, rhs), node.ty)
|
||||||
}
|
}
|
||||||
&ExprKind::Unary { op, arg } if check_unop(op) => {
|
&ExprKind::Unary { op, arg } if check_unop(op) => {
|
||||||
let arg = recurse_build(tcx, body, arg, root_span)?;
|
let arg = recurse_build(tcx, body, arg, root_span)?;
|
||||||
tcx.mk_const(Expr::UnOp(op, arg), node.ty)
|
ty::Const::new_expr(tcx, Expr::UnOp(op, arg), node.ty)
|
||||||
}
|
}
|
||||||
// This is necessary so that the following compiles:
|
// This is necessary so that the following compiles:
|
||||||
//
|
//
|
||||||
|
@ -175,11 +177,11 @@ fn recurse_build<'tcx>(
|
||||||
// This is important so that `N as usize as usize` doesnt unify with `N as usize`. (untested)
|
// This is important so that `N as usize as usize` doesnt unify with `N as usize`. (untested)
|
||||||
&ExprKind::Use { source } => {
|
&ExprKind::Use { source } => {
|
||||||
let arg = recurse_build(tcx, body, source, root_span)?;
|
let arg = recurse_build(tcx, body, source, root_span)?;
|
||||||
tcx.mk_const(Expr::Cast(CastKind::Use, arg, node.ty), node.ty)
|
ty::Const::new_expr(tcx, Expr::Cast(CastKind::Use, arg, node.ty), node.ty)
|
||||||
}
|
}
|
||||||
&ExprKind::Cast { source } => {
|
&ExprKind::Cast { source } => {
|
||||||
let arg = recurse_build(tcx, body, source, root_span)?;
|
let arg = recurse_build(tcx, body, source, root_span)?;
|
||||||
tcx.mk_const(Expr::Cast(CastKind::As, arg, node.ty), node.ty)
|
ty::Const::new_expr(tcx, Expr::Cast(CastKind::As, arg, node.ty), node.ty)
|
||||||
}
|
}
|
||||||
ExprKind::Borrow { arg, .. } => {
|
ExprKind::Borrow { arg, .. } => {
|
||||||
let arg_node = &body.exprs[*arg];
|
let arg_node = &body.exprs[*arg];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue