Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit caa975c

Browse files
committed
use ty::Unevaluated instead of def substs pair
1 parent 0312438 commit caa975c

File tree

19 files changed

+66
-86
lines changed

19 files changed

+66
-86
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
678678
a: ty::Unevaluated<'tcx>,
679679
b: ty::Unevaluated<'tcx>,
680680
) -> bool {
681-
let canonical = self.canonicalize_query(
682-
((a.def, a.substs(self.tcx)), (b.def, b.substs(self.tcx))),
683-
&mut OriginalQueryValues::default(),
684-
);
681+
let canonical = self.canonicalize_query((a, b), &mut OriginalQueryValues::default());
685682
debug!("canonical consts: {:?}", &canonical.value);
686683

687684
self.tcx.try_unify_abstract_consts(canonical.value)

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,11 @@ rustc_queries! {
303303
}
304304

305305
query try_unify_abstract_consts(key: (
306-
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
307-
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)
306+
ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>
308307
)) -> bool {
309308
desc {
310309
|tcx| "trying to unify the generic constants {} and {}",
311-
tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did)
310+
tcx.def_path_str(key.0.def.did), tcx.def_path_str(key.1.def.did)
312311
}
313312
}
314313

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::ScalarInt;
1818
///
1919
/// We check for all possible substs in `fn default_anon_const_substs`,
2020
/// so refer to that check for more info.
21-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
21+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
2222
#[derive(Hash, HashStable)]
2323
pub struct Unevaluated<'tcx> {
2424
pub def: ty::WithOptConstParam<DefId>,

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ impl FlagComputation {
252252
ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => {
253253
self.add_substs(substs);
254254
}
255-
ty::PredicateKind::ConstEvaluatable(_def_id, substs) => {
256-
self.add_substs(substs);
255+
ty::PredicateKind::ConstEvaluatable(uv) => {
256+
self.add_unevaluated_const(uv);
257257
}
258258
ty::PredicateKind::ConstEquate(expected, found) => {
259259
self.add_const(expected);

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ crate struct PredicateInner<'tcx> {
406406
}
407407

408408
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
409-
static_assert_size!(PredicateInner<'_>, 48);
409+
static_assert_size!(PredicateInner<'_>, 56);
410410

411411
#[derive(Clone, Copy, Lift)]
412412
pub struct Predicate<'tcx> {
@@ -502,7 +502,7 @@ pub enum PredicateKind<'tcx> {
502502
Coerce(CoercePredicate<'tcx>),
503503

504504
/// Constant initializer must evaluate successfully.
505-
ConstEvaluatable(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
505+
ConstEvaluatable(ty::Unevaluated<'tcx>),
506506

507507
/// Constants must be equal. The first component is the const that is expected.
508508
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,8 +2294,8 @@ define_print_and_forward_display! {
22942294
print_value_path(closure_def_id, &[]),
22952295
write("` implements the trait `{}`", kind))
22962296
}
2297-
ty::PredicateKind::ConstEvaluatable(def, substs) => {
2298-
p!("the constant `", print_value_path(def.did, substs), "` can be evaluated")
2297+
ty::PredicateKind::ConstEvaluatable(uv) => {
2298+
p!("the constant `", print_value_path(uv.def.did, uv.substs_.map_or(&[], |x| x)), "` can be evaluated")
22992299
}
23002300
ty::PredicateKind::ConstEquate(c1, c2) => {
23012301
p!("the constant `", print(c1), "` equals `", print(c2), "`")

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
579579
(ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu))
580580
if tcx.features().const_evaluatable_checked =>
581581
{
582-
tcx.try_unify_abstract_consts(((au.def, au.substs(tcx)), (bu.def, bu.substs(tcx))))
582+
tcx.try_unify_abstract_consts((au, bu))
583583
}
584584

585585
// While this is slightly incorrect, it shouldn't matter for `min_const_generics`

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
190190
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
191191
write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
192192
}
193-
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
194-
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
193+
ty::PredicateKind::ConstEvaluatable(uv) => {
194+
write!(f, "ConstEvaluatable({:?}, {:?})", uv.def, uv.substs_)
195195
}
196196
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
197197
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
@@ -447,8 +447,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
447447
ty::PredicateKind::ObjectSafe(trait_def_id) => {
448448
Some(ty::PredicateKind::ObjectSafe(trait_def_id))
449449
}
450-
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
451-
tcx.lift(substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs))
450+
ty::PredicateKind::ConstEvaluatable(uv) => {
451+
tcx.lift(uv).map(|uv| ty::PredicateKind::ConstEvaluatable(uv))
452452
}
453453
ty::PredicateKind::ConstEquate(c1, c2) => {
454454
tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))

compiler/rustc_privacy/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ where
134134
ty.visit_with(self)
135135
}
136136
ty::PredicateKind::RegionOutlives(..) => ControlFlow::CONTINUE,
137-
ty::PredicateKind::ConstEvaluatable(defs, substs)
137+
ty::PredicateKind::ConstEvaluatable(uv)
138138
if self.def_id_visitor.tcx().features().const_evaluatable_checked =>
139139
{
140140
let tcx = self.def_id_visitor.tcx();
141-
if let Ok(Some(ct)) = AbstractConst::new(tcx, defs, substs) {
141+
if let Ok(Some(ct)) = AbstractConst::new(tcx, uv) {
142142
self.visit_abstract_const_expr(tcx, ct)?;
143143
}
144144
ControlFlow::CONTINUE

compiler/rustc_query_impl/src/keys.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,13 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
217217
}
218218
}
219219

220-
impl<'tcx> Key
221-
for (
222-
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
223-
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
224-
)
225-
{
220+
impl<'tcx> Key for (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>) {
226221
#[inline(always)]
227222
fn query_crate_is_local(&self) -> bool {
228-
(self.0).0.did.krate == LOCAL_CRATE
223+
(self.0).def.did.krate == LOCAL_CRATE
229224
}
230225
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
231-
(self.0).0.did.default_span(tcx)
226+
(self.0).def.did.default_span(tcx)
232227
}
233228
}
234229

0 commit comments

Comments
 (0)