rename Unevaluated to UnevaluatedConst

This commit is contained in:
b-naber 2022-09-22 12:34:23 +02:00
parent efb908991b
commit a705e65605
35 changed files with 121 additions and 91 deletions

View File

@ -109,7 +109,7 @@ pub(crate) fn codegen_constant<'tcx>(
) -> CValue<'tcx> {
let (const_val, ty) = match fx.monomorphize(constant.literal) {
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) =>
{
assert!(substs.is_empty());

View File

@ -357,7 +357,7 @@ pub fn in_operand<'tcx, Q, F>(
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
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
// check performed after the promotion. Verify that with an assertion.
@ -365,6 +365,7 @@ pub fn in_operand<'tcx, Q, F>(
// Don't peek inside trait associated constants.
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);
if !Q::in_qualifs(&qualifs) {

View File

@ -841,7 +841,7 @@ fn promote_candidate(mut self, candidate: Candidate, next_promoted_id: usize) ->
promoted.span = span;
promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span);
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 {
span,

View File

@ -742,7 +742,7 @@ fn consts(
}
}
}
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }) => {
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
let substs = self.relate_with_variance(
ty::Variance::Invariant,
ty::VarianceDiagInfo::default(),
@ -751,7 +751,7 @@ fn consts(
)?;
Ok(self.tcx().mk_const(ty::ConstS {
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),
@ -962,7 +962,7 @@ fn consts(
}
}
}
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }) => {
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
let substs = self.relate_with_variance(
ty::Variance::Invariant,
ty::VarianceDiagInfo::default(),
@ -972,7 +972,7 @@ fn consts(
Ok(self.tcx().mk_const(ty::ConstS {
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),

View File

@ -705,8 +705,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
#[instrument(skip(self), level = "debug")]
pub fn try_unify_abstract_consts(
&self,
a: ty::Unevaluated<'tcx>,
b: ty::Unevaluated<'tcx>,
a: ty::UnevaluatedConst<'tcx>,
b: ty::UnevaluatedConst<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> bool {
// Reject any attempt to unify two unevaluated constants that contain inference
@ -1690,7 +1690,7 @@ pub fn create_next_universe(&self) -> ty::UniverseIndex {
pub fn try_const_eval_resolve(
&self,
param_env: ty::ParamEnv<'tcx>,
unevaluated: ty::Unevaluated<'tcx>,
unevaluated: ty::UnevaluatedConst<'tcx>,
ty: Ty<'tcx>,
span: Option<Span>,
) -> Result<ty::Const<'tcx>, ErrorHandled> {
@ -1725,7 +1725,7 @@ pub fn try_const_eval_resolve(
pub fn const_eval_resolve(
&self,
mut param_env: ty::ParamEnv<'tcx>,
unevaluated: ty::Unevaluated<'tcx>,
unevaluated: ty::UnevaluatedConst<'tcx>,
span: Option<Span>,
) -> EvalToValTreeResult<'tcx> {
let mut substs = self.resolve_vars_if_possible(unevaluated.substs);
@ -1756,7 +1756,7 @@ pub fn const_eval_resolve(
debug!(?param_env_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
// variables, thus we don't need to substitute back the original values.

View File

@ -36,7 +36,7 @@ pub fn const_eval_poly(self, def_id: DefId) -> EvalToConstValueResult<'tcx> {
pub fn const_eval_resolve(
self,
param_env: ty::ParamEnv<'tcx>,
ct: mir::Unevaluated<'tcx>,
ct: mir::UnevaluatedConst<'tcx>,
span: Option<Span>,
) -> EvalToConstValueResult<'tcx> {
// Cannot resolve `Unevaluated` constants that contain inference
@ -51,7 +51,7 @@ pub fn const_eval_resolve(
match ty::Instance::resolve_opt_const_arg(
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,
) {
Ok(Some(instance)) => {
@ -67,7 +67,7 @@ pub fn const_eval_resolve(
pub fn const_eval_resolve_for_typeck(
self,
param_env: ty::ParamEnv<'tcx>,
ct: ty::Unevaluated<'tcx>,
ct: ty::UnevaluatedConst<'tcx>,
span: Option<Span>,
) -> EvalToValTreeResult<'tcx> {
// Cannot resolve `Unevaluated` constants that contain inference

View File

@ -2055,7 +2055,7 @@ pub enum ConstantKind<'tcx> {
Ty(ty::Const<'tcx>),
/// 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
/// something the type system cannot handle (e.g. pointers).
@ -2315,7 +2315,7 @@ pub fn from_inline_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
ty::InlineConstSubsts::new(tcx, ty::InlineConstSubstsParts { parent_substs, ty })
.substs;
let uneval = Unevaluated {
let uneval = UnevaluatedConst {
def: ty::WithOptConstParam::unknown(def_id).to_global(),
substs,
promoted: None,
@ -2403,7 +2403,7 @@ fn from_opt_const_arg_anon_const(
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
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);
match tcx.const_eval_resolve(param_env, uneval, Some(span)) {
@ -2416,7 +2416,7 @@ fn from_opt_const_arg_anon_const(
// Error was handled in `const_eval_resolve`. Here we just create a
// new unevaluated const and error hard later in codegen
Self::Unevaluated(
Unevaluated {
UnevaluatedConst {
def: def.to_global(),
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
promoted: None,
@ -2442,25 +2442,28 @@ pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
/// An unevaluated (potentially generic) constant used in MIR.
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
#[derive(Hash, HashStable)]
pub struct Unevaluated<'tcx> {
pub struct UnevaluatedConst<'tcx> {
pub def: ty::WithOptConstParam<DefId>,
pub substs: SubstsRef<'tcx>,
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
// shrink and then later expand a promoted.
#[inline]
pub fn shrink(self) -> ty::Unevaluated<'tcx> {
ty::Unevaluated { def: self.def, substs: self.substs }
pub fn shrink(self) -> ty::UnevaluatedConst<'tcx> {
ty::UnevaluatedConst { def: self.def, substs: self.substs }
}
}
impl<'tcx> Unevaluated<'tcx> {
impl<'tcx> UnevaluatedConst<'tcx> {
#[inline]
pub fn new(def: ty::WithOptConstParam<DefId>, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx> {
Unevaluated { def, substs, promoted: Default::default() }
pub fn new(
def: ty::WithOptConstParam<DefId>,
substs: SubstsRef<'tcx>,
) -> UnevaluatedConst<'tcx> {
UnevaluatedConst { def, substs, promoted: Default::default() }
}
}

View File

@ -51,18 +51,18 @@ fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F
}
}
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> {
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>>(
self,
folder: &mut F,
) -> Result<Self, F::Error> {
Ok(mir::Unevaluated {
Ok(mir::UnevaluatedConst {
def: self.def,
substs: self.substs.try_fold_with(folder)?,
promoted: self.promoted,

View File

@ -9,13 +9,13 @@ fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy>
}
}
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> {
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> {
self.substs.visit_with(visitor)
}

View File

@ -381,7 +381,7 @@
}
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 {
desc {
|tcx| "trying to unify the generic constants {} and {}",

View File

@ -30,7 +30,7 @@ pub struct AbstractConst<'tcx> {
impl<'tcx> AbstractConst<'tcx> {
pub fn new(
tcx: TyCtxt<'tcx>,
uv: ty::Unevaluated<'tcx>,
uv: ty::UnevaluatedConst<'tcx>,
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
let inner = tcx.thir_abstract_const_opt_const_arg(uv.def)?;
debug!("AbstractConst::new({:?}) = {:?}", uv, inner);

View File

@ -78,7 +78,7 @@ pub fn from_opt_const_arg_anon_const(
match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v,
None => tcx.mk_const(ty::ConstS {
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst {
def: def.to_global(),
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
}),

View File

@ -15,28 +15,31 @@
/// An unevaluated (potentially generic) constant used in the type-system.
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
#[derive(Hash, HashStable)]
pub struct Unevaluated<'tcx> {
pub struct UnevaluatedConst<'tcx> {
pub def: ty::WithOptConstParam<DefId>,
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> {
format!("{:?}", self).into_diagnostic_arg()
}
}
impl<'tcx> Unevaluated<'tcx> {
impl<'tcx> UnevaluatedConst<'tcx> {
#[inline]
pub fn expand(self) -> mir::Unevaluated<'tcx> {
mir::Unevaluated { def: self.def, substs: self.substs, promoted: None }
pub fn expand(self) -> mir::UnevaluatedConst<'tcx> {
mir::UnevaluatedConst { def: self.def, substs: self.substs, promoted: None }
}
}
impl<'tcx> Unevaluated<'tcx> {
impl<'tcx> UnevaluatedConst<'tcx> {
#[inline]
pub fn new(def: ty::WithOptConstParam<DefId>, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx> {
Unevaluated { def, substs }
pub fn new(
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
/// variants when the code is monomorphic enough for that.
Unevaluated(Unevaluated<'tcx>),
Unevaluated(UnevaluatedConst<'tcx>),
/// Used to hold computed value.
Value(ty::ValTree<'tcx>),
@ -193,7 +196,7 @@ fn try_eval_inner(
// FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
// we can call `infcx.const_eval_resolve` which handles inference variables.
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,
substs: InternalSubsts::identity_for_item(tcx, unevaluated.def.did),
})

View File

@ -34,7 +34,7 @@ pub fn for_const(c: ty::Const<'_>) -> TypeFlags {
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();
result.add_unevaluated_const(uv);
result.flags
@ -313,7 +313,7 @@ fn add_const(&mut self, c: ty::Const<'_>) {
}
}
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_flags(TypeFlags::HAS_CT_PROJECTION);
}

View File

@ -128,11 +128,17 @@ fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
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)
}
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)
}
@ -178,15 +184,15 @@ fn try_fold_const(&mut self, c: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self
fn try_fold_ty_unevaluated(
&mut self,
c: ty::Unevaluated<'tcx>,
) -> Result<ty::Unevaluated<'tcx>, Self::Error> {
c: ty::UnevaluatedConst<'tcx>,
) -> Result<ty::UnevaluatedConst<'tcx>, Self::Error> {
c.try_super_fold_with(self)
}
fn try_fold_mir_unevaluated(
&mut self,
c: mir::Unevaluated<'tcx>,
) -> Result<mir::Unevaluated<'tcx>, Self::Error> {
c: mir::UnevaluatedConst<'tcx>,
) -> Result<mir::UnevaluatedConst<'tcx>, Self::Error> {
c.try_super_fold_with(self)
}
@ -238,15 +244,15 @@ fn try_fold_const(&mut self, c: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, !> {
fn try_fold_ty_unevaluated(
&mut self,
c: ty::Unevaluated<'tcx>,
) -> Result<ty::Unevaluated<'tcx>, !> {
c: ty::UnevaluatedConst<'tcx>,
) -> Result<ty::UnevaluatedConst<'tcx>, !> {
Ok(self.fold_ty_unevaluated(c))
}
fn try_fold_mir_unevaluated(
&mut self,
c: mir::Unevaluated<'tcx>,
) -> Result<mir::Unevaluated<'tcx>, !> {
c: mir::UnevaluatedConst<'tcx>,
) -> Result<mir::UnevaluatedConst<'tcx>, !> {
Ok(self.fold_mir_unevaluated(c))
}

View File

@ -73,7 +73,7 @@
CAPTURE_STRUCT_LOCAL,
};
pub use self::consts::{
Const, ConstInt, ConstKind, ConstS, InferConst, ScalarInt, Unevaluated, ValTree,
Const, ConstInt, ConstKind, ConstS, InferConst, ScalarInt, UnevaluatedConst, ValTree,
};
pub use self::context::{
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
@ -682,7 +682,7 @@ pub enum PredicateKind<'tcx> {
Coerce(CoercePredicate<'tcx>),
/// 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.
ConstEquate(Const<'tcx>, Const<'tcx>),

View File

@ -1201,7 +1201,7 @@ macro_rules! print_underscore {
}
match ct.kind() {
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs }) => {
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
match self.tcx().def_kind(def.did) {
DefKind::Static(..) | DefKind::Const | DefKind::AssocConst => {
p!(print_value_path(def.did, substs))

View File

@ -629,7 +629,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
bu.substs,
)?;
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(),
}));
}

View File

@ -829,28 +829,28 @@ fn visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::B
}
}
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> {
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> {
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>>(
self,
folder: &mut F,
) -> 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> {
self.substs.visit_with(visitor)
}

View File

@ -199,11 +199,17 @@ fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
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)
}
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)
}
@ -601,7 +607,10 @@ fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
#[inline]
#[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);
trace!(r.flags=?flags);
if flags.intersects(self.flags) {
@ -611,7 +620,10 @@ fn visit_ty_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow<Sel
}
}
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());
trace!(r.flags=?flags);
if flags.intersects(self.flags) {

View File

@ -67,7 +67,8 @@ pub(crate) fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'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);
Constant { user_ty, span, literal }
@ -80,7 +81,8 @@ pub(crate) fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> {
Constant { user_ty: None, span, literal }
}
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);
Constant { user_ty: None, span, literal }

View File

@ -301,7 +301,7 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
let lint_only = match c.literal {
ConstantKind::Ty(ct) => ct.needs_subst(),
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

View File

@ -605,7 +605,7 @@ fn dest_needs_borrow(place: Place<'_>) -> bool {
caller_body.required_consts.extend(
callee_body.required_consts.iter().copied().filter(|&ct| match ct.literal {
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,
}),

View File

@ -300,7 +300,7 @@ fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow<Self::BreakTy> {
self.unused_parameters.clear(param.index);
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) =>
{
self.visit_child_body(def.did, substs);
@ -317,7 +317,7 @@ fn visit_mir_const(&mut self, constant: ConstantKind<'tcx>) -> ControlFlow<Self:
match constant {
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:
// `<Self as Foo<T>>::foo::promoted[p]`
if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self =>

View File

@ -276,7 +276,7 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
}
}
impl<'tcx> Key for (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>) {
impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) {
#[inline(always)]
fn query_crate_is_local(&self) -> bool {
(self.0).def.did.krate == LOCAL_CRATE

View File

@ -1,6 +1,6 @@
use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_macros::Diagnostic;
use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
use rustc_middle::ty::{self, PolyTraitRef, Ty};
use rustc_session::Limit;
use rustc_span::{Span, Symbol};
@ -18,7 +18,7 @@ pub struct DumpVTableEntries<'a> {
pub struct UnableToConstructConstantValue<'a> {
#[primary_span]
pub span: Span,
pub unevaluated: Unevaluated<'a>,
pub unevaluated: ty::UnevaluatedConst<'a>,
}
#[derive(Diagnostic)]

View File

@ -138,7 +138,7 @@ pub fn try_unify(&self, a: AbstractConst<'tcx>, b: AbstractConst<'tcx>) -> bool
#[instrument(skip(tcx), level = "debug")]
pub fn try_unify_abstract_consts<'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>,
) -> bool {
(|| {
@ -161,7 +161,7 @@ pub fn try_unify_abstract_consts<'tcx>(
#[instrument(skip(infcx), level = "debug")]
pub fn is_const_evaluatable<'cx, 'tcx>(
infcx: &InferCtxt<'cx, 'tcx>,
uv: ty::Unevaluated<'tcx>,
uv: ty::UnevaluatedConst<'tcx>,
param_env: ty::ParamEnv<'tcx>,
span: Span,
) -> Result<(), NotConstEvaluatable> {

View File

@ -840,7 +840,7 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
fn visit_ty_unevaluated(
&mut self,
uv: ty::Unevaluated<'tcx>,
uv: ty::UnevaluatedConst<'tcx>,
) -> ControlFlow<Self::BreakTy> {
// Constants can only influence object safety if they reference `Self`.
// This is only possible for unevaluated constants, so we walk these here.

View File

@ -2141,7 +2141,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
let identity_substs =
crate::traits::InternalSubsts::identity_for_item(tcx, 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())
} else {
ty.map_bound(|ty| ty.into())

View File

@ -258,7 +258,8 @@ fn recurse_build(&mut self, node: thir::ExprId) -> Result<NodeId, ErrorGuarantee
self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, val, node.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
.tcx

View File

@ -1113,10 +1113,12 @@ fn check_type_defn<'tcx, F>(
wfcx.register_obligation(traits::Obligation::new(
cause,
wfcx.param_env,
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ty::Unevaluated::new(
ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
discr_substs,
)))
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(
ty::UnevaluatedConst::new(
ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
discr_substs,
),
))
.to_predicate(tcx),
));
}

View File

@ -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 {
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() {
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(def.did))
} else {

View File

@ -2,7 +2,7 @@
| 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">}
| 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() -> () {
let mut _0: (); // return place in scope 0 at $DIR/issue-99325.rs:+0:15: +0:15

View File

@ -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(
cx.param_env,
mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
None,
);
is_value_unfrozen_raw(cx, result, ty)

View File

@ -424,7 +424,7 @@ fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option<C
.tcx
.const_eval_resolve(
self.param_env,
mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
None,
)
.ok()