Skip to content

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

-1
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

+2-2
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

+1-1
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

+1-8
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

+1-1
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

+1-1
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

+4
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

+26-2
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

+1-1
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

+1-1
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)?

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn encode_const<'tcx>(
112112
let _ = write!(s, "{value}");
113113
}
114114

115-
if let Some(scalar_int) = c.kind().try_to_scalar_int() {
115+
if let Some(scalar_int) = c.try_to_scalar_int() {
116116
let signed = c.ty().is_signed();
117117
match scalar_int.size().bits() {
118118
8 if signed => push_signed_value(&mut s, scalar_int.try_to_i8().unwrap(), 0),
@@ -504,8 +504,7 @@ fn encode_ty<'tcx>(
504504
let _ = write!(
505505
s,
506506
"{}",
507-
&len.kind()
508-
.try_to_scalar()
507+
&len.try_to_scalar()
509508
.unwrap()
510509
.to_u64()
511510
.unwrap_or_else(|_| panic!("failed to convert length to u64"))
@@ -815,7 +814,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
815814

816815
ty::Array(ty0, len) => {
817816
let len = len
818-
.kind()
819817
.try_to_scalar()
820818
.unwrap()
821819
.to_u64()

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
651651
.builtin_deref(true)
652652
.expect("tried to dereference on non-ptr type")
653653
.ty;
654-
// FIXME: add an assert that we only do this for valtrees.
654+
// FIXME(const_generics): add an assert that we only do this for valtrees.
655655
let dereferenced_const = self.tcx.mk_ct_from_kind(ct.kind(), pointee_ty);
656656
self = dereferenced_const.print(self)?;
657657
}

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
278278
// Arrays give us `[]`, `[{ty}; _]` and `[{ty}; N]`
279279
if let ty::Array(aty, len) = self_ty.kind() {
280280
flags.push((sym::_Self, Some("[]".to_string())));
281-
let len = len.kind().try_to_value().and_then(|v| v.try_to_target_usize(self.tcx));
281+
let len = len.try_to_value().and_then(|v| v.try_to_target_usize(self.tcx));
282282
flags.push((sym::_Self, Some(format!("[{}; _]", aty))));
283283
if let Some(n) = len {
284284
flags.push((sym::_Self, Some(format!("[{}; {}]", aty, n))));

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
528528
debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2);
529529

530530
use rustc_hir::def::DefKind;
531-
use ty::ConstKind::Unevaluated;
531+
use ty::Unevaluated;
532532
match (c1.kind(), c2.kind()) {
533533
(Unevaluated(a), Unevaluated(b))
534534
if a.def == b.def && tcx.def_kind(a.def) == DefKind::AssocConst =>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
897897
);
898898

899899
use rustc_hir::def::DefKind;
900-
use ty::ConstKind::Unevaluated;
900+
use ty::Unevaluated;
901901
match (c1.kind(), c2.kind()) {
902902
(Unevaluated(a), Unevaluated(b))
903903
if a.def == b.def && tcx.def_kind(a.def) == DefKind::AssocConst =>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t
689689
mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() {
690690
ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)),
691691
ty::Array(sub_type, len) => match sub_type.kind() {
692-
ty::Float(FloatTy::F32) => match len.kind().try_to_target_usize(lcx.tcx) {
692+
ty::Float(FloatTy::F32) => match len.try_to_target_usize(lcx.tcx) {
693693
Some(len) => alloc
694694
.inner()
695695
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap()))
@@ -700,7 +700,7 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t
700700
.map(Constant::Vec),
701701
_ => None,
702702
},
703-
ty::Float(FloatTy::F64) => match len.kind().try_to_target_usize(lcx.tcx) {
703+
ty::Float(FloatTy::F64) => match len.try_to_target_usize(lcx.tcx) {
704704
Some(len) => alloc
705705
.inner()
706706
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap()))

tests/mir-opt/issue_99325.main.built.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| User Type Annotations
44
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)]) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated([], DefId(0:8 ~ issue_99325[22bb]::main::{constant#1})) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), substs: [] } }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

0 commit comments

Comments
 (0)