Skip to content

Commit 7c9b5b4

Browse files
committed
update const_eval_resolve
1 parent 43ebac1 commit 7c9b5b4

File tree

13 files changed

+45
-55
lines changed

13 files changed

+45
-55
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
4545
};
4646
match const_.val {
4747
ConstKind::Value(_) => {}
48-
ConstKind::Unevaluated(def, ref substs, promoted) => {
48+
ConstKind::Unevaluated(unevaluated) => {
4949
if let Err(err) =
50-
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None)
50+
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None)
5151
{
5252
all_constants_ok = false;
5353
match err {
@@ -122,14 +122,14 @@ pub(crate) fn codegen_constant<'tcx>(
122122
};
123123
let const_val = match const_.val {
124124
ConstKind::Value(const_val) => const_val,
125-
ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => {
125+
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) if fx.tcx.is_static(def.did) => {
126126
assert!(substs.is_empty());
127127
assert!(promoted.is_none());
128128

129129
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty)).to_cvalue(fx);
130130
}
131-
ConstKind::Unevaluated(def, ref substs, promoted) => {
132-
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
131+
ConstKind::Unevaluated(unevaluated) => {
132+
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
133133
Ok(const_val) => const_val,
134134
Err(_) => {
135135
span_bug!(constant.span, "erroneous constant not captured by required_consts");

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3030
mir::ConstantKind::Val(val, _) => return Ok(val),
3131
};
3232
match ct.val {
33-
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => self
33+
ty::ConstKind::Unevaluated(ct) => self
3434
.cx
3535
.tcx()
36-
.const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None)
36+
.const_eval_resolve(ty::ParamEnv::reveal_all(), ct, None)
3737
.map_err(|err| {
3838
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
3939
err

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1818
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
1919
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
2020
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
21-
use rustc_middle::mir;
2221
use rustc_middle::mir::interpret::EvalToConstValueResult;
2322
use rustc_middle::traits::select;
2423
use rustc_middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
@@ -1499,9 +1498,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14991498
pub fn const_eval_resolve(
15001499
&self,
15011500
param_env: ty::ParamEnv<'tcx>,
1502-
def: ty::WithOptConstParam<DefId>,
1503-
substs: SubstsRef<'tcx>,
1504-
promoted: Option<mir::Promoted>,
1501+
ty::Unevaluated { def, substs, promoted }: ty::Unevaluated<'tcx>,
15051502
span: Option<Span>,
15061503
) -> EvalToConstValueResult<'tcx> {
15071504
let mut original_values = OriginalQueryValues::default();
@@ -1510,7 +1507,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15101507
let (param_env, substs) = canonical.value;
15111508
// The return value is the evaluated value which doesn't contain any reference to inference
15121509
// variables, thus we don't need to substitute back the original values.
1513-
self.tcx.const_eval_resolve(param_env, def, substs, promoted, span)
1510+
self.tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, span)
15141511
}
15151512

15161513
/// If `typ` is a type variable of some kind, resolve it one level

compiler/rustc_middle/src/mir/interpret/queries.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{ErrorHandled, EvalToConstValueResult, GlobalId};
22

33
use crate::mir;
4-
use crate::ty::subst::{InternalSubsts, SubstsRef};
4+
use crate::ty::subst::InternalSubsts;
55
use crate::ty::{self, TyCtxt};
66
use rustc_hir::def_id::DefId;
77
use rustc_span::Span;
@@ -35,14 +35,12 @@ impl<'tcx> TyCtxt<'tcx> {
3535
pub fn const_eval_resolve(
3636
self,
3737
param_env: ty::ParamEnv<'tcx>,
38-
def: ty::WithOptConstParam<DefId>,
39-
substs: SubstsRef<'tcx>,
40-
promoted: Option<mir::Promoted>,
38+
ct: ty::Unevaluated<'tcx>,
4139
span: Option<Span>,
4240
) -> EvalToConstValueResult<'tcx> {
43-
match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) {
41+
match ty::Instance::resolve_opt_const_arg(self, param_env, ct.def, ct.substs) {
4442
Ok(Some(instance)) => {
45-
let cid = GlobalId { instance, promoted };
43+
let cid = GlobalId { instance, promoted: ct.promoted };
4644
self.const_eval_global_id(param_env, cid, span)
4745
}
4846
Ok(None) => Err(ErrorHandled::TooGeneric),

compiler/rustc_middle/src/ty/consts/kind.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ impl<'tcx> ConstKind<'tcx> {
140140
let (param_env, substs) = param_env_and_substs.into_parts();
141141
// try to resolve e.g. associated constants to their definition on an impl, and then
142142
// evaluate the const.
143-
match tcx.const_eval_resolve(param_env, def, substs, promoted, None) {
143+
match tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, None)
144+
{
144145
// NOTE(eddyb) `val` contains no lifetimes/types/consts,
145146
// and we use the original type, so nothing from `substs`
146147
// (which may be identity substs, see above),

compiler/rustc_mir/src/monomorphize/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
646646

647647
match substituted_constant.val {
648648
ty::ConstKind::Value(val) => collect_const_value(self.tcx, val, self.output),
649-
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => {
650-
match self.tcx.const_eval_resolve(param_env, def, substs, promoted, None) {
649+
ty::ConstKind::Unevaluated(unevaluated) => {
650+
match self.tcx.const_eval_resolve(param_env, unevaluated, None) {
651651
Ok(val) => collect_const_value(self.tcx, val, self.output),
652652
Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted) => {}
653653
Err(ErrorHandled::TooGeneric) => span_bug!(

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,10 @@ impl AutoTraitFinder<'tcx> {
803803
}
804804
ty::PredicateKind::ConstEquate(c1, c2) => {
805805
let evaluate = |c: &'tcx ty::Const<'tcx>| {
806-
if let ty::ConstKind::Unevaluated(ty::Unevaluated {
807-
def,
808-
substs,
809-
promoted,
810-
}) = c.val
811-
{
806+
if let ty::ConstKind::Unevaluated(unevaluated) = c.val {
812807
match select.infcx().const_eval_resolve(
813808
obligation.param_env,
814-
def,
815-
substs,
816-
promoted,
809+
unevaluated,
817810
Some(obligation.cause.span),
818811
) {
819812
Ok(val) => Ok(ty::Const::from_value(select.tcx(), val, c.ty)),

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
163163
// and hopefully soon change this to an error.
164164
//
165165
// See #74595 for more details about this.
166-
let concrete = infcx.const_eval_resolve(param_env, def, substs, None, Some(span));
166+
let concrete = infcx.const_eval_resolve(
167+
param_env,
168+
ty::Unevaluated { def, substs, promoted: None },
169+
Some(span),
170+
);
167171

168172
if concrete.is_ok() && substs.has_param_types_or_consts() {
169173
match infcx.tcx.def_kind(def.did) {

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -532,23 +532,17 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
532532
let stalled_on = &mut pending_obligation.stalled_on;
533533

534534
let mut evaluate = |c: &'tcx Const<'tcx>| {
535-
if let ty::ConstKind::Unevaluated(ty::Unevaluated {
536-
def,
537-
substs,
538-
promoted,
539-
}) = c.val
540-
{
535+
if let ty::ConstKind::Unevaluated(unevaluated) = c.val {
541536
match self.selcx.infcx().const_eval_resolve(
542537
obligation.param_env,
543-
def,
544-
substs,
545-
promoted,
538+
unevaluated,
546539
Some(obligation.cause.span),
547540
) {
548541
Ok(val) => Ok(Const::from_value(self.selcx.tcx(), val, c.ty)),
549542
Err(ErrorHandled::TooGeneric) => {
550543
stalled_on.extend(
551-
substs
544+
unevaluated
545+
.substs
552546
.iter()
553547
.filter_map(TyOrConstInferVar::maybe_from_generic_arg),
554548
);

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
556556
debug!(?c1, ?c2, "evaluate_predicate_recursively: equating consts");
557557

558558
let evaluate = |c: &'tcx ty::Const<'tcx>| {
559-
if let ty::ConstKind::Unevaluated(ty::Unevaluated {
560-
def,
561-
substs,
562-
promoted,
563-
}) = c.val
564-
{
559+
if let ty::ConstKind::Unevaluated(unevaluated) = c.val {
565560
self.infcx
566561
.const_eval_resolve(
567562
obligation.param_env,
568-
def,
569-
substs,
570-
promoted,
563+
unevaluated,
571564
Some(obligation.cause.span),
572565
)
573566
.map(|val| ty::Const::from_value(self.tcx(), val, c.ty))

src/librustdoc/clean/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
296296

297297
crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
298298
match n.val {
299-
ty::ConstKind::Unevaluated(def, _, promoted) => {
299+
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => {
300300
let mut s = if let Some(def) = def.as_local() {
301301
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did);
302302
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(hir_id))

src/tools/clippy/clippy_lints/src/non_copy_const.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,15 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D
181181

182182
let result = cx
183183
.tcx
184-
.const_eval_resolve(cx.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None);
184+
.const_eval_resolve(
185+
cx.param_env,
186+
ty::Unevaluated {
187+
def: ty::WithOptConstParam::unknown(def_id),
188+
substs,
189+
promoted: None
190+
},
191+
None
192+
);
185193
is_value_unfrozen_raw(cx, result, ty)
186194
}
187195

src/tools/clippy/clippy_utils/src/consts.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,11 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
341341
.tcx
342342
.const_eval_resolve(
343343
self.param_env,
344-
ty::WithOptConstParam::unknown(def_id),
345-
substs,
346-
None,
344+
ty::Unevaluated {
345+
def: ty::WithOptConstParam::unknown(def_id),
346+
substs,
347+
promoted: None,
348+
},
347349
None,
348350
)
349351
.ok()

0 commit comments

Comments
 (0)