mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-19 18:34:08 +00:00
rename Unevaluated to UnevaluatedConst
This commit is contained in:
parent
efb908991b
commit
a705e65605
@ -109,7 +109,7 @@ pub(crate) fn codegen_constant<'tcx>(
|
|||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
let (const_val, ty) = match fx.monomorphize(constant.literal) {
|
let (const_val, ty) = match fx.monomorphize(constant.literal) {
|
||||||
ConstantKind::Ty(const_) => unreachable!("{:?}", const_),
|
ConstantKind::Ty(const_) => unreachable!("{:?}", const_),
|
||||||
ConstantKind::Unevaluated(mir::Unevaluated { def, substs, promoted }, ty)
|
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, substs, promoted }, ty)
|
||||||
if fx.tcx.is_static(def.did) =>
|
if fx.tcx.is_static(def.did) =>
|
||||||
{
|
{
|
||||||
assert!(substs.is_empty());
|
assert!(substs.is_empty());
|
||||||
|
@ -357,7 +357,7 @@ where
|
|||||||
ConstantKind::Val(..) => None,
|
ConstantKind::Val(..) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(mir::Unevaluated { def, substs: _, promoted }) = uneval {
|
if let Some(mir::UnevaluatedConst { def, substs: _, promoted }) = uneval {
|
||||||
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
|
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
|
||||||
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
|
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
|
||||||
// check performed after the promotion. Verify that with an assertion.
|
// check performed after the promotion. Verify that with an assertion.
|
||||||
@ -365,6 +365,7 @@ where
|
|||||||
|
|
||||||
// Don't peek inside trait associated constants.
|
// Don't peek inside trait associated constants.
|
||||||
if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() {
|
if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() {
|
||||||
|
assert_eq!(def.const_param_did, None, "expected associated const: {def:?}");
|
||||||
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def.did);
|
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def.did);
|
||||||
|
|
||||||
if !Q::in_qualifs(&qualifs) {
|
if !Q::in_qualifs(&qualifs) {
|
||||||
|
@ -841,7 +841,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||||||
promoted.span = span;
|
promoted.span = span;
|
||||||
promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span);
|
promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span);
|
||||||
let substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def.did));
|
let substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def.did));
|
||||||
let uneval = mir::Unevaluated { def, substs, promoted: Some(promoted_id) };
|
let uneval = mir::UnevaluatedConst { def, substs, promoted: Some(promoted_id) };
|
||||||
|
|
||||||
Operand::Constant(Box::new(Constant {
|
Operand::Constant(Box::new(Constant {
|
||||||
span,
|
span,
|
||||||
|
@ -742,7 +742,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }) => {
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
|
||||||
let substs = self.relate_with_variance(
|
let substs = self.relate_with_variance(
|
||||||
ty::Variance::Invariant,
|
ty::Variance::Invariant,
|
||||||
ty::VarianceDiagInfo::default(),
|
ty::VarianceDiagInfo::default(),
|
||||||
@ -751,7 +751,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||||||
)?;
|
)?;
|
||||||
Ok(self.tcx().mk_const(ty::ConstS {
|
Ok(self.tcx().mk_const(ty::ConstS {
|
||||||
ty: c.ty(),
|
ty: c.ty(),
|
||||||
kind: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }),
|
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
_ => relate::super_relate_consts(self, c, c),
|
_ => relate::super_relate_consts(self, c, c),
|
||||||
@ -962,7 +962,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }) => {
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
|
||||||
let substs = self.relate_with_variance(
|
let substs = self.relate_with_variance(
|
||||||
ty::Variance::Invariant,
|
ty::Variance::Invariant,
|
||||||
ty::VarianceDiagInfo::default(),
|
ty::VarianceDiagInfo::default(),
|
||||||
@ -972,7 +972,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
|||||||
|
|
||||||
Ok(self.tcx().mk_const(ty::ConstS {
|
Ok(self.tcx().mk_const(ty::ConstS {
|
||||||
ty: c.ty(),
|
ty: c.ty(),
|
||||||
kind: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }),
|
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
_ => relate::super_relate_consts(self, c, c),
|
_ => relate::super_relate_consts(self, c, c),
|
||||||
|
@ -705,8 +705,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn try_unify_abstract_consts(
|
pub fn try_unify_abstract_consts(
|
||||||
&self,
|
&self,
|
||||||
a: ty::Unevaluated<'tcx>,
|
a: ty::UnevaluatedConst<'tcx>,
|
||||||
b: ty::Unevaluated<'tcx>,
|
b: ty::UnevaluatedConst<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// Reject any attempt to unify two unevaluated constants that contain inference
|
// Reject any attempt to unify two unevaluated constants that contain inference
|
||||||
@ -1690,7 +1690,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
pub fn try_const_eval_resolve(
|
pub fn try_const_eval_resolve(
|
||||||
&self,
|
&self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
unevaluated: ty::Unevaluated<'tcx>,
|
unevaluated: ty::UnevaluatedConst<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
) -> Result<ty::Const<'tcx>, ErrorHandled> {
|
) -> Result<ty::Const<'tcx>, ErrorHandled> {
|
||||||
@ -1725,7 +1725,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
pub fn const_eval_resolve(
|
pub fn const_eval_resolve(
|
||||||
&self,
|
&self,
|
||||||
mut param_env: ty::ParamEnv<'tcx>,
|
mut param_env: ty::ParamEnv<'tcx>,
|
||||||
unevaluated: ty::Unevaluated<'tcx>,
|
unevaluated: ty::UnevaluatedConst<'tcx>,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
) -> EvalToValTreeResult<'tcx> {
|
) -> EvalToValTreeResult<'tcx> {
|
||||||
let mut substs = self.resolve_vars_if_possible(unevaluated.substs);
|
let mut substs = self.resolve_vars_if_possible(unevaluated.substs);
|
||||||
@ -1756,7 +1756,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
debug!(?param_env_erased);
|
debug!(?param_env_erased);
|
||||||
debug!(?substs_erased);
|
debug!(?substs_erased);
|
||||||
|
|
||||||
let unevaluated = ty::Unevaluated { def: unevaluated.def, substs: substs_erased };
|
let unevaluated = ty::UnevaluatedConst { def: unevaluated.def, substs: substs_erased };
|
||||||
|
|
||||||
// The return value is the evaluated value which doesn't contain any reference to inference
|
// The return value is the evaluated value which doesn't contain any reference to inference
|
||||||
// variables, thus we don't need to substitute back the original values.
|
// variables, thus we don't need to substitute back the original values.
|
||||||
|
@ -36,7 +36,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
pub fn const_eval_resolve(
|
pub fn const_eval_resolve(
|
||||||
self,
|
self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
ct: mir::Unevaluated<'tcx>,
|
ct: mir::UnevaluatedConst<'tcx>,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
) -> EvalToConstValueResult<'tcx> {
|
) -> EvalToConstValueResult<'tcx> {
|
||||||
// Cannot resolve `Unevaluated` constants that contain inference
|
// Cannot resolve `Unevaluated` constants that contain inference
|
||||||
@ -51,7 +51,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
match ty::Instance::resolve_opt_const_arg(
|
match ty::Instance::resolve_opt_const_arg(
|
||||||
self, param_env,
|
self, param_env,
|
||||||
// FIXME: maybe have a seperate version for resolving mir::Unevaluated?
|
// FIXME: maybe have a seperate version for resolving mir::UnevaluatedConst?
|
||||||
ct.def, ct.substs,
|
ct.def, ct.substs,
|
||||||
) {
|
) {
|
||||||
Ok(Some(instance)) => {
|
Ok(Some(instance)) => {
|
||||||
@ -67,7 +67,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
pub fn const_eval_resolve_for_typeck(
|
pub fn const_eval_resolve_for_typeck(
|
||||||
self,
|
self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
ct: ty::Unevaluated<'tcx>,
|
ct: ty::UnevaluatedConst<'tcx>,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
) -> EvalToValTreeResult<'tcx> {
|
) -> EvalToValTreeResult<'tcx> {
|
||||||
// Cannot resolve `Unevaluated` constants that contain inference
|
// Cannot resolve `Unevaluated` constants that contain inference
|
||||||
|
@ -2055,7 +2055,7 @@ pub enum ConstantKind<'tcx> {
|
|||||||
Ty(ty::Const<'tcx>),
|
Ty(ty::Const<'tcx>),
|
||||||
|
|
||||||
/// An unevaluated mir constant which is not part of the type system.
|
/// An unevaluated mir constant which is not part of the type system.
|
||||||
Unevaluated(Unevaluated<'tcx>, Ty<'tcx>),
|
Unevaluated(UnevaluatedConst<'tcx>, Ty<'tcx>),
|
||||||
|
|
||||||
/// This constant cannot go back into the type system, as it represents
|
/// This constant cannot go back into the type system, as it represents
|
||||||
/// something the type system cannot handle (e.g. pointers).
|
/// something the type system cannot handle (e.g. pointers).
|
||||||
@ -2315,7 +2315,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||||||
ty::InlineConstSubsts::new(tcx, ty::InlineConstSubstsParts { parent_substs, ty })
|
ty::InlineConstSubsts::new(tcx, ty::InlineConstSubstsParts { parent_substs, ty })
|
||||||
.substs;
|
.substs;
|
||||||
|
|
||||||
let uneval = Unevaluated {
|
let uneval = UnevaluatedConst {
|
||||||
def: ty::WithOptConstParam::unknown(def_id).to_global(),
|
def: ty::WithOptConstParam::unknown(def_id).to_global(),
|
||||||
substs,
|
substs,
|
||||||
promoted: None,
|
promoted: None,
|
||||||
@ -2403,7 +2403,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||||||
|
|
||||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
||||||
let span = tcx.hir().span(hir_id);
|
let span = tcx.hir().span(hir_id);
|
||||||
let uneval = Unevaluated::new(def.to_global(), substs);
|
let uneval = UnevaluatedConst::new(def.to_global(), substs);
|
||||||
debug!(?span, ?param_env);
|
debug!(?span, ?param_env);
|
||||||
|
|
||||||
match tcx.const_eval_resolve(param_env, uneval, Some(span)) {
|
match tcx.const_eval_resolve(param_env, uneval, Some(span)) {
|
||||||
@ -2416,7 +2416,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||||||
// Error was handled in `const_eval_resolve`. Here we just create a
|
// Error was handled in `const_eval_resolve`. Here we just create a
|
||||||
// new unevaluated const and error hard later in codegen
|
// new unevaluated const and error hard later in codegen
|
||||||
Self::Unevaluated(
|
Self::Unevaluated(
|
||||||
Unevaluated {
|
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()),
|
||||||
promoted: None,
|
promoted: None,
|
||||||
@ -2442,25 +2442,28 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||||||
/// An unevaluated (potentially generic) constant used in MIR.
|
/// An unevaluated (potentially generic) constant used in MIR.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
|
||||||
#[derive(Hash, HashStable)]
|
#[derive(Hash, HashStable)]
|
||||||
pub struct Unevaluated<'tcx> {
|
pub struct UnevaluatedConst<'tcx> {
|
||||||
pub def: ty::WithOptConstParam<DefId>,
|
pub def: ty::WithOptConstParam<DefId>,
|
||||||
pub substs: SubstsRef<'tcx>,
|
pub substs: SubstsRef<'tcx>,
|
||||||
pub promoted: Option<Promoted>,
|
pub promoted: Option<Promoted>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Unevaluated<'tcx> {
|
impl<'tcx> UnevaluatedConst<'tcx> {
|
||||||
// FIXME: probably should get rid of this method. It's also wrong to
|
// FIXME: probably should get rid of this method. It's also wrong to
|
||||||
// shrink and then later expand a promoted.
|
// shrink and then later expand a promoted.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn shrink(self) -> ty::Unevaluated<'tcx> {
|
pub fn shrink(self) -> ty::UnevaluatedConst<'tcx> {
|
||||||
ty::Unevaluated { def: self.def, substs: self.substs }
|
ty::UnevaluatedConst { def: self.def, substs: self.substs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Unevaluated<'tcx> {
|
impl<'tcx> UnevaluatedConst<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(def: ty::WithOptConstParam<DefId>, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx> {
|
pub fn new(
|
||||||
Unevaluated { def, substs, promoted: Default::default() }
|
def: ty::WithOptConstParam<DefId>,
|
||||||
|
substs: SubstsRef<'tcx>,
|
||||||
|
) -> UnevaluatedConst<'tcx> {
|
||||||
|
UnevaluatedConst { def, substs, promoted: Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,18 +51,18 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for mir::Unevaluated<'tcx> {
|
impl<'tcx> TypeFoldable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
folder.try_fold_mir_unevaluated(self)
|
folder.try_fold_mir_unevaluated(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeSuperFoldable<'tcx> for mir::Unevaluated<'tcx> {
|
impl<'tcx> TypeSuperFoldable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
||||||
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
|
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
|
||||||
self,
|
self,
|
||||||
folder: &mut F,
|
folder: &mut F,
|
||||||
) -> Result<Self, F::Error> {
|
) -> Result<Self, F::Error> {
|
||||||
Ok(mir::Unevaluated {
|
Ok(mir::UnevaluatedConst {
|
||||||
def: self.def,
|
def: self.def,
|
||||||
substs: self.substs.try_fold_with(folder)?,
|
substs: self.substs.try_fold_with(folder)?,
|
||||||
promoted: self.promoted,
|
promoted: self.promoted,
|
||||||
|
@ -9,13 +9,13 @@ impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for mir::Unevaluated<'tcx> {
|
impl<'tcx> TypeVisitable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
visitor.visit_mir_unevaluated(*self)
|
visitor.visit_mir_unevaluated(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeSuperVisitable<'tcx> for mir::Unevaluated<'tcx> {
|
impl<'tcx> TypeSuperVisitable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
||||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
self.substs.visit_with(visitor)
|
self.substs.visit_with(visitor)
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ rustc_queries! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
query try_unify_abstract_consts(key:
|
query try_unify_abstract_consts(key:
|
||||||
ty::ParamEnvAnd<'tcx, (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>
|
ty::ParamEnvAnd<'tcx, (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>
|
||||||
)>) -> bool {
|
)>) -> bool {
|
||||||
desc {
|
desc {
|
||||||
|tcx| "trying to unify the generic constants {} and {}",
|
|tcx| "trying to unify the generic constants {} and {}",
|
||||||
|
@ -30,7 +30,7 @@ pub struct AbstractConst<'tcx> {
|
|||||||
impl<'tcx> AbstractConst<'tcx> {
|
impl<'tcx> AbstractConst<'tcx> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
uv: ty::Unevaluated<'tcx>,
|
uv: ty::UnevaluatedConst<'tcx>,
|
||||||
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
|
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
|
||||||
let inner = tcx.thir_abstract_const_opt_const_arg(uv.def)?;
|
let inner = tcx.thir_abstract_const_opt_const_arg(uv.def)?;
|
||||||
debug!("AbstractConst::new({:?}) = {:?}", uv, inner);
|
debug!("AbstractConst::new({:?}) = {:?}", uv, inner);
|
||||||
|
@ -78,7 +78,7 @@ 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(ty::ConstS {
|
||||||
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
|
kind: 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()),
|
||||||
}),
|
}),
|
||||||
|
@ -15,28 +15,31 @@ use super::ScalarInt;
|
|||||||
/// An unevaluated (potentially generic) constant used in the type-system.
|
/// An unevaluated (potentially generic) constant used in the type-system.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
|
||||||
#[derive(Hash, HashStable)]
|
#[derive(Hash, HashStable)]
|
||||||
pub struct Unevaluated<'tcx> {
|
pub struct UnevaluatedConst<'tcx> {
|
||||||
pub def: ty::WithOptConstParam<DefId>,
|
pub def: ty::WithOptConstParam<DefId>,
|
||||||
pub substs: SubstsRef<'tcx>,
|
pub substs: SubstsRef<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl rustc_errors::IntoDiagnosticArg for Unevaluated<'_> {
|
impl rustc_errors::IntoDiagnosticArg for UnevaluatedConst<'_> {
|
||||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
||||||
format!("{:?}", self).into_diagnostic_arg()
|
format!("{:?}", self).into_diagnostic_arg()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Unevaluated<'tcx> {
|
impl<'tcx> UnevaluatedConst<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn expand(self) -> mir::Unevaluated<'tcx> {
|
pub fn expand(self) -> mir::UnevaluatedConst<'tcx> {
|
||||||
mir::Unevaluated { def: self.def, substs: self.substs, promoted: None }
|
mir::UnevaluatedConst { def: self.def, substs: self.substs, promoted: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Unevaluated<'tcx> {
|
impl<'tcx> UnevaluatedConst<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(def: ty::WithOptConstParam<DefId>, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx> {
|
pub fn new(
|
||||||
Unevaluated { def, substs }
|
def: ty::WithOptConstParam<DefId>,
|
||||||
|
substs: SubstsRef<'tcx>,
|
||||||
|
) -> UnevaluatedConst<'tcx> {
|
||||||
|
UnevaluatedConst { def, substs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +61,7 @@ pub enum ConstKind<'tcx> {
|
|||||||
|
|
||||||
/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
|
/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
|
||||||
/// variants when the code is monomorphic enough for that.
|
/// variants when the code is monomorphic enough for that.
|
||||||
Unevaluated(Unevaluated<'tcx>),
|
Unevaluated(UnevaluatedConst<'tcx>),
|
||||||
|
|
||||||
/// Used to hold computed value.
|
/// Used to hold computed value.
|
||||||
Value(ty::ValTree<'tcx>),
|
Value(ty::ValTree<'tcx>),
|
||||||
@ -193,7 +196,7 @@ impl<'tcx> ConstKind<'tcx> {
|
|||||||
// FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
|
// FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
|
||||||
// we can call `infcx.const_eval_resolve` which handles inference variables.
|
// we can call `infcx.const_eval_resolve` which handles inference variables.
|
||||||
let param_env_and = if param_env_and.needs_infer() {
|
let param_env_and = if param_env_and.needs_infer() {
|
||||||
tcx.param_env(unevaluated.def.did).and(ty::Unevaluated {
|
tcx.param_env(unevaluated.def.did).and(ty::UnevaluatedConst {
|
||||||
def: unevaluated.def,
|
def: unevaluated.def,
|
||||||
substs: InternalSubsts::identity_for_item(tcx, unevaluated.def.did),
|
substs: InternalSubsts::identity_for_item(tcx, unevaluated.def.did),
|
||||||
})
|
})
|
||||||
|
@ -34,7 +34,7 @@ impl FlagComputation {
|
|||||||
result.flags
|
result.flags
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn for_unevaluated_const(uv: ty::Unevaluated<'_>) -> TypeFlags {
|
pub fn for_unevaluated_const(uv: ty::UnevaluatedConst<'_>) -> TypeFlags {
|
||||||
let mut result = FlagComputation::new();
|
let mut result = FlagComputation::new();
|
||||||
result.add_unevaluated_const(uv);
|
result.add_unevaluated_const(uv);
|
||||||
result.flags
|
result.flags
|
||||||
@ -313,7 +313,7 @@ impl FlagComputation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_unevaluated_const(&mut self, ct: ty::Unevaluated<'_>) {
|
fn add_unevaluated_const(&mut self, ct: ty::UnevaluatedConst<'_>) {
|
||||||
self.add_substs(ct.substs);
|
self.add_substs(ct.substs);
|
||||||
self.add_flags(TypeFlags::HAS_CT_PROJECTION);
|
self.add_flags(TypeFlags::HAS_CT_PROJECTION);
|
||||||
}
|
}
|
||||||
|
@ -128,11 +128,17 @@ pub trait TypeFolder<'tcx>: FallibleTypeFolder<'tcx, Error = !> {
|
|||||||
c.super_fold_with(self)
|
c.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_ty_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ty::Unevaluated<'tcx> {
|
fn fold_ty_unevaluated(
|
||||||
|
&mut self,
|
||||||
|
uv: ty::UnevaluatedConst<'tcx>,
|
||||||
|
) -> ty::UnevaluatedConst<'tcx> {
|
||||||
uv.super_fold_with(self)
|
uv.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_mir_unevaluated(&mut self, uv: mir::Unevaluated<'tcx>) -> mir::Unevaluated<'tcx> {
|
fn fold_mir_unevaluated(
|
||||||
|
&mut self,
|
||||||
|
uv: mir::UnevaluatedConst<'tcx>,
|
||||||
|
) -> mir::UnevaluatedConst<'tcx> {
|
||||||
uv.super_fold_with(self)
|
uv.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,15 +184,15 @@ pub trait FallibleTypeFolder<'tcx>: Sized {
|
|||||||
|
|
||||||
fn try_fold_ty_unevaluated(
|
fn try_fold_ty_unevaluated(
|
||||||
&mut self,
|
&mut self,
|
||||||
c: ty::Unevaluated<'tcx>,
|
c: ty::UnevaluatedConst<'tcx>,
|
||||||
) -> Result<ty::Unevaluated<'tcx>, Self::Error> {
|
) -> Result<ty::UnevaluatedConst<'tcx>, Self::Error> {
|
||||||
c.try_super_fold_with(self)
|
c.try_super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_unevaluated(
|
fn try_fold_mir_unevaluated(
|
||||||
&mut self,
|
&mut self,
|
||||||
c: mir::Unevaluated<'tcx>,
|
c: mir::UnevaluatedConst<'tcx>,
|
||||||
) -> Result<mir::Unevaluated<'tcx>, Self::Error> {
|
) -> Result<mir::UnevaluatedConst<'tcx>, Self::Error> {
|
||||||
c.try_super_fold_with(self)
|
c.try_super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,15 +244,15 @@ where
|
|||||||
|
|
||||||
fn try_fold_ty_unevaluated(
|
fn try_fold_ty_unevaluated(
|
||||||
&mut self,
|
&mut self,
|
||||||
c: ty::Unevaluated<'tcx>,
|
c: ty::UnevaluatedConst<'tcx>,
|
||||||
) -> Result<ty::Unevaluated<'tcx>, !> {
|
) -> Result<ty::UnevaluatedConst<'tcx>, !> {
|
||||||
Ok(self.fold_ty_unevaluated(c))
|
Ok(self.fold_ty_unevaluated(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_unevaluated(
|
fn try_fold_mir_unevaluated(
|
||||||
&mut self,
|
&mut self,
|
||||||
c: mir::Unevaluated<'tcx>,
|
c: mir::UnevaluatedConst<'tcx>,
|
||||||
) -> Result<mir::Unevaluated<'tcx>, !> {
|
) -> Result<mir::UnevaluatedConst<'tcx>, !> {
|
||||||
Ok(self.fold_mir_unevaluated(c))
|
Ok(self.fold_mir_unevaluated(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ pub use self::closure::{
|
|||||||
CAPTURE_STRUCT_LOCAL,
|
CAPTURE_STRUCT_LOCAL,
|
||||||
};
|
};
|
||||||
pub use self::consts::{
|
pub use self::consts::{
|
||||||
Const, ConstInt, ConstKind, ConstS, InferConst, ScalarInt, Unevaluated, ValTree,
|
Const, ConstInt, ConstKind, ConstS, InferConst, ScalarInt, UnevaluatedConst, ValTree,
|
||||||
};
|
};
|
||||||
pub use self::context::{
|
pub use self::context::{
|
||||||
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
|
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
|
||||||
@ -682,7 +682,7 @@ pub enum PredicateKind<'tcx> {
|
|||||||
Coerce(CoercePredicate<'tcx>),
|
Coerce(CoercePredicate<'tcx>),
|
||||||
|
|
||||||
/// Constant initializer must evaluate successfully.
|
/// Constant initializer must evaluate successfully.
|
||||||
ConstEvaluatable(ty::Unevaluated<'tcx>),
|
ConstEvaluatable(ty::UnevaluatedConst<'tcx>),
|
||||||
|
|
||||||
/// Constants must be equal. The first component is the const that is expected.
|
/// Constants must be equal. The first component is the const that is expected.
|
||||||
ConstEquate(Const<'tcx>, Const<'tcx>),
|
ConstEquate(Const<'tcx>, Const<'tcx>),
|
||||||
|
@ -1201,7 +1201,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
}
|
}
|
||||||
|
|
||||||
match ct.kind() {
|
match ct.kind() {
|
||||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }) => {
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
|
||||||
match self.tcx().def_kind(def.did) {
|
match self.tcx().def_kind(def.did) {
|
||||||
DefKind::Static(..) | DefKind::Const | DefKind::AssocConst => {
|
DefKind::Static(..) | DefKind::Const | DefKind::AssocConst => {
|
||||||
p!(print_value_path(def.did, substs))
|
p!(print_value_path(def.did, substs))
|
||||||
|
@ -629,7 +629,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
|
|||||||
bu.substs,
|
bu.substs,
|
||||||
)?;
|
)?;
|
||||||
return Ok(tcx.mk_const(ty::ConstS {
|
return Ok(tcx.mk_const(ty::ConstS {
|
||||||
kind: ty::ConstKind::Unevaluated(ty::Unevaluated { def: au.def, substs }),
|
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def: au.def, substs }),
|
||||||
ty: a.ty(),
|
ty: a.ty(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -829,28 +829,28 @@ impl<'tcx> TypeVisitable<'tcx> for InferConst<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> {
|
impl<'tcx> TypeFoldable<'tcx> for ty::UnevaluatedConst<'tcx> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
folder.try_fold_ty_unevaluated(self)
|
folder.try_fold_ty_unevaluated(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for ty::Unevaluated<'tcx> {
|
impl<'tcx> TypeVisitable<'tcx> for ty::UnevaluatedConst<'tcx> {
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
visitor.visit_ty_unevaluated(*self)
|
visitor.visit_ty_unevaluated(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeSuperFoldable<'tcx> for ty::Unevaluated<'tcx> {
|
impl<'tcx> TypeSuperFoldable<'tcx> for ty::UnevaluatedConst<'tcx> {
|
||||||
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
|
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
|
||||||
self,
|
self,
|
||||||
folder: &mut F,
|
folder: &mut F,
|
||||||
) -> Result<Self, F::Error> {
|
) -> Result<Self, F::Error> {
|
||||||
Ok(ty::Unevaluated { def: self.def, substs: self.substs.try_fold_with(folder)? })
|
Ok(ty::UnevaluatedConst { def: self.def, substs: self.substs.try_fold_with(folder)? })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeSuperVisitable<'tcx> for ty::Unevaluated<'tcx> {
|
impl<'tcx> TypeSuperVisitable<'tcx> for ty::UnevaluatedConst<'tcx> {
|
||||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
self.substs.visit_with(visitor)
|
self.substs.visit_with(visitor)
|
||||||
}
|
}
|
||||||
|
@ -199,11 +199,17 @@ pub trait TypeVisitor<'tcx>: Sized {
|
|||||||
c.super_visit_with(self)
|
c.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty_unevaluated(
|
||||||
|
&mut self,
|
||||||
|
uv: ty::UnevaluatedConst<'tcx>,
|
||||||
|
) -> ControlFlow<Self::BreakTy> {
|
||||||
uv.super_visit_with(self)
|
uv.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mir_unevaluated(&mut self, uv: mir::Unevaluated<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_mir_unevaluated(
|
||||||
|
&mut self,
|
||||||
|
uv: mir::UnevaluatedConst<'tcx>,
|
||||||
|
) -> ControlFlow<Self::BreakTy> {
|
||||||
uv.super_visit_with(self)
|
uv.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,7 +607,10 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[instrument(level = "trace", ret)]
|
#[instrument(level = "trace", ret)]
|
||||||
fn visit_ty_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty_unevaluated(
|
||||||
|
&mut self,
|
||||||
|
uv: ty::UnevaluatedConst<'tcx>,
|
||||||
|
) -> ControlFlow<Self::BreakTy> {
|
||||||
let flags = FlagComputation::for_unevaluated_const(uv);
|
let flags = FlagComputation::for_unevaluated_const(uv);
|
||||||
trace!(r.flags=?flags);
|
trace!(r.flags=?flags);
|
||||||
if flags.intersects(self.flags) {
|
if flags.intersects(self.flags) {
|
||||||
@ -611,7 +620,10 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mir_unevaluated(&mut self, uv: mir::Unevaluated<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_mir_unevaluated(
|
||||||
|
&mut self,
|
||||||
|
uv: mir::UnevaluatedConst<'tcx>,
|
||||||
|
) -> ControlFlow<Self::BreakTy> {
|
||||||
let flags = FlagComputation::for_unevaluated_const(uv.shrink());
|
let flags = FlagComputation::for_unevaluated_const(uv.shrink());
|
||||||
trace!(r.flags=?flags);
|
trace!(r.flags=?flags);
|
||||||
if flags.intersects(self.flags) {
|
if flags.intersects(self.flags) {
|
||||||
|
@ -67,7 +67,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let uneval = mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
|
let uneval =
|
||||||
|
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
|
||||||
let literal = ConstantKind::Unevaluated(uneval, ty);
|
let literal = ConstantKind::Unevaluated(uneval, ty);
|
||||||
|
|
||||||
Constant { user_ty, span, literal }
|
Constant { user_ty, span, literal }
|
||||||
@ -80,7 +81,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
Constant { user_ty: None, span, literal }
|
Constant { user_ty: None, span, literal }
|
||||||
}
|
}
|
||||||
ExprKind::ConstBlock { did: def_id, substs } => {
|
ExprKind::ConstBlock { did: def_id, substs } => {
|
||||||
let uneval = mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
|
let uneval =
|
||||||
|
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
|
||||||
let literal = ConstantKind::Unevaluated(uneval, ty);
|
let literal = ConstantKind::Unevaluated(uneval, ty);
|
||||||
|
|
||||||
Constant { user_ty: None, span, literal }
|
Constant { user_ty: None, span, literal }
|
||||||
|
@ -301,7 +301,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||||||
let lint_only = match c.literal {
|
let lint_only = match c.literal {
|
||||||
ConstantKind::Ty(ct) => ct.needs_subst(),
|
ConstantKind::Ty(ct) => ct.needs_subst(),
|
||||||
ConstantKind::Unevaluated(
|
ConstantKind::Unevaluated(
|
||||||
mir::Unevaluated { def: _, substs: _, promoted: Some(_) },
|
mir::UnevaluatedConst { def: _, substs: _, promoted: Some(_) },
|
||||||
_,
|
_,
|
||||||
) => {
|
) => {
|
||||||
// Promoteds must lint and not error as the user didn't ask for them
|
// Promoteds must lint and not error as the user didn't ask for them
|
||||||
|
@ -605,7 +605,7 @@ impl<'tcx> Inliner<'tcx> {
|
|||||||
caller_body.required_consts.extend(
|
caller_body.required_consts.extend(
|
||||||
callee_body.required_consts.iter().copied().filter(|&ct| match ct.literal {
|
callee_body.required_consts.iter().copied().filter(|&ct| match ct.literal {
|
||||||
ConstantKind::Ty(_) => {
|
ConstantKind::Ty(_) => {
|
||||||
bug!("should never encounter ty::Unevaluated in `required_consts`")
|
bug!("should never encounter ty::UnevaluatedConst in `required_consts`")
|
||||||
}
|
}
|
||||||
ConstantKind::Val(..) | ConstantKind::Unevaluated(..) => true,
|
ConstantKind::Val(..) | ConstantKind::Unevaluated(..) => true,
|
||||||
}),
|
}),
|
||||||
|
@ -300,7 +300,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||||||
self.unused_parameters.clear(param.index);
|
self.unused_parameters.clear(param.index);
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
}
|
}
|
||||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs })
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs })
|
||||||
if matches!(self.tcx.def_kind(def.did), DefKind::AnonConst) =>
|
if matches!(self.tcx.def_kind(def.did), DefKind::AnonConst) =>
|
||||||
{
|
{
|
||||||
self.visit_child_body(def.did, substs);
|
self.visit_child_body(def.did, substs);
|
||||||
@ -317,7 +317,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||||||
|
|
||||||
match constant {
|
match constant {
|
||||||
ConstantKind::Ty(ct) => ct.visit_with(self),
|
ConstantKind::Ty(ct) => ct.visit_with(self),
|
||||||
ConstantKind::Unevaluated(mir::Unevaluated { def, substs: _, promoted: Some(p) }, _)
|
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, substs: _, promoted: Some(p) }, _)
|
||||||
// Avoid considering `T` unused when constants are of the form:
|
// Avoid considering `T` unused when constants are of the form:
|
||||||
// `<Self as Foo<T>>::foo::promoted[p]`
|
// `<Self as Foo<T>>::foo::promoted[p]`
|
||||||
if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self =>
|
if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self =>
|
||||||
|
@ -276,7 +276,7 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>) {
|
impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn query_crate_is_local(&self) -> bool {
|
fn query_crate_is_local(&self) -> bool {
|
||||||
(self.0).def.did.krate == LOCAL_CRATE
|
(self.0).def.did.krate == LOCAL_CRATE
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
|
use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
|
||||||
use rustc_macros::Diagnostic;
|
use rustc_macros::Diagnostic;
|
||||||
use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
|
use rustc_middle::ty::{self, PolyTraitRef, Ty};
|
||||||
use rustc_session::Limit;
|
use rustc_session::Limit;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ pub struct DumpVTableEntries<'a> {
|
|||||||
pub struct UnableToConstructConstantValue<'a> {
|
pub struct UnableToConstructConstantValue<'a> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub unevaluated: Unevaluated<'a>,
|
pub unevaluated: ty::UnevaluatedConst<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -138,7 +138,7 @@ impl<'tcx> ConstUnifyCtxt<'tcx> {
|
|||||||
#[instrument(skip(tcx), level = "debug")]
|
#[instrument(skip(tcx), level = "debug")]
|
||||||
pub fn try_unify_abstract_consts<'tcx>(
|
pub fn try_unify_abstract_consts<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
(a, b): (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>),
|
(a, b): (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>),
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
(|| {
|
(|| {
|
||||||
@ -161,7 +161,7 @@ pub fn try_unify_abstract_consts<'tcx>(
|
|||||||
#[instrument(skip(infcx), level = "debug")]
|
#[instrument(skip(infcx), level = "debug")]
|
||||||
pub fn is_const_evaluatable<'cx, 'tcx>(
|
pub fn is_const_evaluatable<'cx, 'tcx>(
|
||||||
infcx: &InferCtxt<'cx, 'tcx>,
|
infcx: &InferCtxt<'cx, 'tcx>,
|
||||||
uv: ty::Unevaluated<'tcx>,
|
uv: ty::UnevaluatedConst<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<(), NotConstEvaluatable> {
|
) -> Result<(), NotConstEvaluatable> {
|
||||||
|
@ -840,7 +840,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeVisitable<'tcx>>(
|
|||||||
|
|
||||||
fn visit_ty_unevaluated(
|
fn visit_ty_unevaluated(
|
||||||
&mut self,
|
&mut self,
|
||||||
uv: ty::Unevaluated<'tcx>,
|
uv: ty::UnevaluatedConst<'tcx>,
|
||||||
) -> ControlFlow<Self::BreakTy> {
|
) -> ControlFlow<Self::BreakTy> {
|
||||||
// Constants can only influence object safety if they reference `Self`.
|
// Constants can only influence object safety if they reference `Self`.
|
||||||
// This is only possible for unevaluated constants, so we walk these here.
|
// This is only possible for unevaluated constants, so we walk these here.
|
||||||
|
@ -2141,7 +2141,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
|||||||
let identity_substs =
|
let identity_substs =
|
||||||
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::Unevaluated::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(ty::ConstS { ty, kind }).into())
|
||||||
} else {
|
} else {
|
||||||
ty.map_bound(|ty| ty.into())
|
ty.map_bound(|ty| ty.into())
|
||||||
|
@ -258,7 +258,8 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
|||||||
self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, val, node.ty)))
|
self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, val, node.ty)))
|
||||||
}
|
}
|
||||||
&ExprKind::NamedConst { def_id, substs, user_ty: _ } => {
|
&ExprKind::NamedConst { def_id, substs, user_ty: _ } => {
|
||||||
let uneval = ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
|
let uneval =
|
||||||
|
ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
|
||||||
|
|
||||||
let constant = self
|
let constant = self
|
||||||
.tcx
|
.tcx
|
||||||
|
@ -1113,10 +1113,12 @@ fn check_type_defn<'tcx, F>(
|
|||||||
wfcx.register_obligation(traits::Obligation::new(
|
wfcx.register_obligation(traits::Obligation::new(
|
||||||
cause,
|
cause,
|
||||||
wfcx.param_env,
|
wfcx.param_env,
|
||||||
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ty::Unevaluated::new(
|
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(
|
||||||
ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
|
ty::UnevaluatedConst::new(
|
||||||
discr_substs,
|
ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
|
||||||
)))
|
discr_substs,
|
||||||
|
),
|
||||||
|
))
|
||||||
.to_predicate(tcx),
|
.to_predicate(tcx),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
|
|||||||
|
|
||||||
pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
|
pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
|
||||||
match n.kind() {
|
match n.kind() {
|
||||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _ }) => {
|
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs: _ }) => {
|
||||||
let s = if let Some(def) = def.as_local() {
|
let s = if let Some(def) = def.as_local() {
|
||||||
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(def.did))
|
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(def.did))
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
| User Type Annotations
|
| User Type Annotations
|
||||||
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Value(Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)])) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Value(Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)])) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
||||||
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [] }) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated(UnevaluatedConst { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [] }) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
||||||
|
|
|
|
||||||
fn main() -> () {
|
fn main() -> () {
|
||||||
let mut _0: (); // return place in scope 0 at $DIR/issue-99325.rs:+0:15: +0:15
|
let mut _0: (); // return place in scope 0 at $DIR/issue-99325.rs:+0:15: +0:15
|
||||||
|
@ -195,7 +195,7 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D
|
|||||||
|
|
||||||
let result = cx.tcx.const_eval_resolve(
|
let result = cx.tcx.const_eval_resolve(
|
||||||
cx.param_env,
|
cx.param_env,
|
||||||
mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
|
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
is_value_unfrozen_raw(cx, result, ty)
|
is_value_unfrozen_raw(cx, result, ty)
|
||||||
|
@ -424,7 +424,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
|||||||
.tcx
|
.tcx
|
||||||
.const_eval_resolve(
|
.const_eval_resolve(
|
||||||
self.param_env,
|
self.param_env,
|
||||||
mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
|
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
|
Loading…
Reference in New Issue
Block a user