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

Commit 62174bf

Browse files
committed
Deal with fallout
1 parent 8ac3ffe commit 62174bf

File tree

17 files changed

+47
-29
lines changed

17 files changed

+47
-29
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ fn codegen_stmt<'tcx>(
706706
let times = fx
707707
.monomorphize(times)
708708
.eval(fx.tcx, ParamEnv::reveal_all())
709-
.kind()
710709
.try_to_bits(fx.tcx.data_layout.pointer_size)
711710
.unwrap();
712711
if operand.layout().size.bytes() == 0 {

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@ impl<'tcx> ConstantKind<'tcx> {
23292329
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
23302330
match self {
23312331
Self::Ty(c) => {
2332-
if let Some(val) = c.kind().try_eval_for_mir(tcx, param_env) {
2332+
if let Some(val) = c.try_eval_for_mir(tcx, param_env) {
23332333
match val {
23342334
Ok(val) => Self::Val(val, c.ty()),
23352335
Err(guar) => Self::Ty(ty::Const::new_error(tcx, guar, self.ty())),
@@ -2867,7 +2867,7 @@ fn pretty_print_const_value<'tcx>(
28672867
}
28682868
}
28692869
(ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if *t == u8_type => {
2870-
let n = n.kind().try_to_bits(tcx.data_layout.pointer_size).unwrap();
2870+
let n = n.try_to_bits(tcx.data_layout.pointer_size).unwrap();
28712871
// cast is ok because we already checked for pointer size (32 or 64 bit) above
28722872
let range = AllocRange { start: offset, size: Size::from_bytes(n) };
28732873
let byte_str = alloc.inner().get_bytes_strip_provenance(&tcx, range).unwrap();

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'tcx> Const<'tcx> {
5454

5555
#[inline]
5656
pub fn kind(self) -> ConstKind<'tcx> {
57-
self.0.kind
57+
self.0.kind.clone()
5858
}
5959

6060
#[inline]

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::Const;
22
use crate::mir;
33
use crate::ty::abstract_const::CastKind;
4-
use crate::ty::sty::ConstKind;
54
use crate::ty::subst::SubstsRef;
65
use crate::ty::{self, List, Ty};
76
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -36,12 +35,6 @@ impl<'tcx> UnevaluatedConst<'tcx> {
3635
}
3736
}
3837

39-
impl<'tcx> From<ty::ConstVid<'tcx>> for ConstKind<'tcx> {
40-
fn from(const_vid: ty::ConstVid<'tcx>) -> Self {
41-
InferConst::Var(const_vid).into()
42-
}
43-
}
44-
4538
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
4639
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
4740
pub enum Expr<'tcx> {
@@ -55,7 +48,7 @@ pub enum Expr<'tcx> {
5548
static_assert_size!(Expr<'_>, 24);
5649

5750
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
58-
static_assert_size!(ConstKind<'_>, 32);
51+
static_assert_size!(super::ConstKind<'_>, 32);
5952

6053
/// An inference variable for a const, for use in const generics.
6154
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Hash)]

compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'tcx> InhabitedPredicate<'tcx> {
170170
match self {
171171
Self::ConstIsZero(c) => {
172172
let c = ty::EarlyBinder::bind(c).subst(tcx, substs);
173-
let pred = match c.kind().try_to_target_usize(tcx) {
173+
let pred = match c.try_to_target_usize(tcx) {
174174
Some(0) => Self::True,
175175
Some(1..) => Self::False,
176176
None => Self::ConstIsZero(c),

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn inhabited_predicate_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> InhabitedP
197197

198198
// If we can evaluate the array length before having a `ParamEnv`, then
199199
// we can simplify the predicate. This is an optimization.
200-
Array(ty, len) => match len.kind().try_to_target_usize(tcx) {
200+
Array(ty, len) => match len.try_to_target_usize(tcx) {
201201
Some(0) => InhabitedPredicate::True,
202202
Some(1..) => ty.inhabited_predicate(tcx),
203203
None => ty.inhabited_predicate(tcx).or(tcx, InhabitedPredicate::ConstIsZero(len)),

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ use std::{fmt, str};
6666

6767
pub use crate::ty::diagnostics::*;
6868
pub use rustc_type_ir::AliasKind::*;
69+
pub use rustc_type_ir::ConstKind::{
70+
Bound as BoundCt, Error as ErrorCt, Expr as ExprCt, Infer as InferCt, Param as ParamCt,
71+
Placeholder as PlaceholderCt, Unevaluated, Value,
72+
};
6973
pub use rustc_type_ir::DynKind::*;
7074
pub use rustc_type_ir::InferTy::*;
7175
pub use rustc_type_ir::RegionKind::*;

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
1111
use rustc_hir::def::Namespace;
1212
use rustc_index::{Idx, IndexVec};
1313
use rustc_target::abi::TyAndLayout;
14+
use rustc_type_ir::ConstKind;
1415

1516
use std::fmt;
1617
use std::ops::ControlFlow;
@@ -710,7 +711,18 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
710711
folder: &mut F,
711712
) -> Result<Self, F::Error> {
712713
let ty = self.ty().try_fold_with(folder)?;
713-
let kind = self.kind().try_fold_with(folder)?;
714+
let kind = match self.kind() {
715+
ConstKind::Param(p) => ConstKind::Param(p.try_fold_with(folder)?),
716+
ConstKind::Infer(i) => ConstKind::Infer(i.try_fold_with(folder)?),
717+
ConstKind::Bound(d, b) => {
718+
ConstKind::Bound(d.try_fold_with(folder)?, b.try_fold_with(folder)?)
719+
}
720+
ConstKind::Placeholder(p) => ConstKind::Placeholder(p.try_fold_with(folder)?),
721+
ConstKind::Unevaluated(uv) => ConstKind::Unevaluated(uv.try_fold_with(folder)?),
722+
ConstKind::Value(v) => ConstKind::Value(v.try_fold_with(folder)?),
723+
ConstKind::Error(e) => ConstKind::Error(e.try_fold_with(folder)?),
724+
ConstKind::Expr(e) => ConstKind::Expr(e.try_fold_with(folder)?),
725+
};
714726
if ty != self.ty() || kind != self.kind() {
715727
Ok(folder.interner().mk_ct_from_kind(kind, ty))
716728
} else {
@@ -725,7 +737,19 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
725737
visitor: &mut V,
726738
) -> ControlFlow<V::BreakTy> {
727739
self.ty().visit_with(visitor)?;
728-
self.kind().visit_with(visitor)
740+
match self.kind() {
741+
ConstKind::Param(p) => p.visit_with(visitor),
742+
ConstKind::Infer(i) => i.visit_with(visitor),
743+
ConstKind::Bound(d, b) => {
744+
d.visit_with(visitor)?;
745+
b.visit_with(visitor)
746+
}
747+
ConstKind::Placeholder(p) => p.visit_with(visitor),
748+
ConstKind::Unevaluated(uv) => uv.visit_with(visitor),
749+
ConstKind::Value(v) => v.visit_with(visitor),
750+
ConstKind::Error(e) => e.visit_with(visitor),
751+
ConstKind::Expr(e) => e.visit_with(visitor),
752+
}
729753
}
730754
}
731755

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ pub fn needs_drop_components<'tcx>(
13061306
ty::Array(elem_ty, size) => {
13071307
match needs_drop_components(*elem_ty, target_layout) {
13081308
Ok(v) if v.is_empty() => Ok(v),
1309-
res => match size.kind().try_to_bits(target_layout.pointer_size) {
1309+
res => match size.try_to_bits(target_layout.pointer_size) {
13101310
// Arrays of size zero don't need drop, even if their element
13111311
// type does.
13121312
Some(0) => Ok(SmallVec::new()),

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
230230
self.write_str("[")?;
231231
self = self.print_type(ty)?;
232232
self.write_str("; ")?;
233-
if let Some(size) = size.kind().try_to_bits(self.tcx().data_layout.pointer_size) {
233+
if let Some(size) = size.try_to_bits(self.tcx().data_layout.pointer_size) {
234234
write!(self, "{size}")?
235235
} else if let ty::ConstKind::Param(param) = size.kind() {
236236
self = param.print(self)?

0 commit comments

Comments
 (0)