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

Commit 660ca48

Browse files
committed
change ConstEvaluatable to use ty::Const
1 parent 98a5ac2 commit 660ca48

File tree

15 files changed

+62
-42
lines changed

15 files changed

+62
-42
lines changed

compiler/rustc_hir_analysis/src/check/dropck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
198198
(
199199
ty::PredicateKind::ConstEvaluatable(a),
200200
ty::PredicateKind::ConstEvaluatable(b),
201-
) => tcx.try_unify_abstract_consts(self_param_env.and((a, b))),
201+
) => relator.relate(predicate.rebind(a), predicate.rebind(b)).is_ok(),
202202
(
203203
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, lt_a)),
204204
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_b, lt_b)),

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,6 @@ fn check_type_defn<'tcx, F>(
11011101

11021102
// Explicit `enum` discriminant values must const-evaluate successfully.
11031103
if let Some(discr_def_id) = variant.explicit_discr {
1104-
let discr_substs = InternalSubsts::identity_for_item(tcx, discr_def_id.to_def_id());
1105-
11061104
let cause = traits::ObligationCause::new(
11071105
tcx.def_span(discr_def_id),
11081106
wfcx.body_id,
@@ -1112,10 +1110,7 @@ fn check_type_defn<'tcx, F>(
11121110
cause,
11131111
wfcx.param_env,
11141112
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(
1115-
ty::UnevaluatedConst::new(
1116-
ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
1117-
discr_substs,
1118-
),
1113+
ty::Const::from_anon_const(tcx, discr_def_id),
11191114
))
11201115
.to_predicate(tcx),
11211116
));

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ fn const_evaluatable_predicates_of<'tcx>(
318318
fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
319319
let def_id = self.tcx.hir().local_def_id(c.hir_id);
320320
let ct = ty::Const::from_anon_const(self.tcx, def_id);
321-
if let ty::ConstKind::Unevaluated(uv) = ct.kind() {
321+
if let ty::ConstKind::Unevaluated(_) = ct.kind() {
322322
let span = self.tcx.hir().span(c.hir_id);
323323
self.preds.insert((
324-
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(uv))
324+
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct))
325325
.to_predicate(self.tcx),
326326
span,
327327
));

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ impl<'tcx> Const<'tcx> {
263263
self.try_eval_usize(tcx, param_env)
264264
.unwrap_or_else(|| bug!("expected usize, got {:#?}", self))
265265
}
266+
267+
pub fn is_ct_infer(self) -> bool {
268+
matches!(self.kind(), ty::ConstKind::Infer(_))
269+
}
266270
}
267271

268272
pub fn const_param_default<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Const<'tcx> {

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl FlagComputation {
256256
self.add_substs(substs);
257257
}
258258
ty::PredicateKind::ConstEvaluatable(uv) => {
259-
self.add_unevaluated_const(uv);
259+
self.add_const(uv);
260260
}
261261
ty::PredicateKind::ConstEquate(expected, found) => {
262262
self.add_const(expected);

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ pub enum PredicateKind<'tcx> {
682682
Coerce(CoercePredicate<'tcx>),
683683

684684
/// Constant initializer must evaluate successfully.
685-
ConstEvaluatable(ty::UnevaluatedConst<'tcx>),
685+
ConstEvaluatable(ty::Const<'tcx>),
686686

687687
/// Constants must be equal. The first component is the const that is expected.
688688
ConstEquate(Const<'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
@@ -2702,8 +2702,8 @@ define_print_and_forward_display! {
27022702
print_value_path(closure_def_id, &[]),
27032703
write("` implements the trait `{}`", kind))
27042704
}
2705-
ty::PredicateKind::ConstEvaluatable(uv) => {
2706-
p!("the constant `", print_value_path(uv.def.did, uv.substs), "` can be evaluated")
2705+
ty::PredicateKind::ConstEvaluatable(ct) => {
2706+
p!("the constant `", print(ct), "` can be evaluated")
27072707
}
27082708
ty::PredicateKind::ConstEquate(c1, c2) => {
27092709
p!("the constant `", print(c1), "` equals `", print(c2), "`")

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
166166
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
167167
write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
168168
}
169-
ty::PredicateKind::ConstEvaluatable(uv) => {
170-
write!(f, "ConstEvaluatable({:?}, {:?})", uv.def, uv.substs)
169+
ty::PredicateKind::ConstEvaluatable(ct) => {
170+
write!(f, "ConstEvaluatable({ct:?})")
171171
}
172172
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
173173
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {

compiler/rustc_middle/src/ty/subst.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ impl<'tcx> GenericArg<'tcx> {
188188
_ => bug!("expected a const, but found another kind"),
189189
}
190190
}
191+
192+
pub fn is_non_region_infer(self) -> bool {
193+
match self.unpack() {
194+
GenericArgKind::Lifetime(_) => false,
195+
GenericArgKind::Type(ty) => ty.is_ty_infer(),
196+
GenericArgKind::Const(ct) => ct.is_ct_infer(),
197+
}
198+
}
191199
}
192200

193201
impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {

compiler/rustc_middle/src/ty/walk.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ impl<'tcx> Ty<'tcx> {
112112
}
113113
}
114114

115+
impl<'tcx> ty::Const<'tcx> {
116+
/// Iterator that walks `self` and any types reachable from
117+
/// `self`, in depth-first order. Note that just walks the types
118+
/// that appear in `self`, it does not descend into the fields of
119+
/// structs or variants. For example:
120+
///
121+
/// ```text
122+
/// isize => { isize }
123+
/// Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
124+
/// [isize] => { [isize], isize }
125+
/// ```
126+
pub fn walk(self) -> TypeWalker<'tcx> {
127+
TypeWalker::new(self.into())
128+
}
129+
}
130+
115131
/// We push `GenericArg`s on the stack in reverse order so as to
116132
/// maintain a pre-order traversal. As of the time of this
117133
/// writing, the fact that the traversal is pre-order is not

0 commit comments

Comments
 (0)