Skip to content

Commit c30c1be

Browse files
committed
s/ConstantSource/ConstantKind/
1 parent 11ddd22 commit c30c1be

File tree

11 files changed

+43
-51
lines changed

11 files changed

+43
-51
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
4040
let mut all_constants_ok = true;
4141
for constant in &fx.mir.required_consts {
4242
let const_ = match fx.monomorphize(constant.literal) {
43-
ConstantSource::Ty(ct) => ct,
44-
ConstantSource::Val(..) => continue,
43+
ConstantKind::Ty(ct) => ct,
44+
ConstantKind::Val(..) => continue,
4545
};
4646
match const_.val {
4747
ConstKind::Value(_) => {}
@@ -117,8 +117,8 @@ pub(crate) fn codegen_constant<'tcx>(
117117
constant: &Constant<'tcx>,
118118
) -> CValue<'tcx> {
119119
let const_ = match fx.monomorphize(constant.literal) {
120-
ConstantSource::Ty(ct) => ct,
121-
ConstantSource::Val(val, ty) => return codegen_const_value(fx, val, ty),
120+
ConstantKind::Ty(ct) => ct,
121+
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
122122
};
123123
let const_val = match const_.val {
124124
ConstKind::Value(const_val) => const_val,
@@ -427,10 +427,10 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
427427
match operand {
428428
Operand::Copy(_) | Operand::Move(_) => None,
429429
Operand::Constant(const_) => match const_.literal {
430-
ConstantSource::Ty(const_) => {
430+
ConstantKind::Ty(const_) => {
431431
fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val.try_to_value()
432432
}
433-
ConstantSource::Val(val, _) => Some(val),
433+
ConstantKind::Val(val, _) => Some(val),
434434
},
435435
}
436436
}

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2626
) -> Result<ConstValue<'tcx>, ErrorHandled> {
2727
let ct = self.monomorphize(constant.literal);
2828
let ct = match ct {
29-
mir::ConstantSource::Ty(ct) => ct,
30-
mir::ConstantSource::Val(val, _) => return Ok(val),
29+
mir::ConstantKind::Ty(ct) => ct,
30+
mir::ConstantKind::Val(val, _) => return Ok(val),
3131
};
3232
match ct.val {
3333
ty::ConstKind::Unevaluated(def, substs, promoted) => self

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,6 @@ impl<'tcx, Tag> Scalar<Tag> {
381381
self.to_bits(target_size).expect("expected Raw bits but got a Pointer")
382382
}
383383

384-
#[inline]
385-
pub fn to_int(self) -> InterpResult<'tcx, ScalarInt> {
386-
match self {
387-
Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes),
388-
Scalar::Int(int) => Ok(int),
389-
}
390-
}
391-
392384
#[inline]
393385
pub fn assert_int(self) -> ScalarInt {
394386
self.to_int().expect("expected an int but got an abstract pointer")

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ impl<'tcx> Operand<'tcx> {
20332033
Operand::Constant(box Constant {
20342034
span,
20352035
user_ty: None,
2036-
literal: ConstantSource::Ty(ty::Const::zero_sized(tcx, ty)),
2036+
literal: ConstantKind::Ty(ty::Const::zero_sized(tcx, ty)),
20372037
})
20382038
}
20392039

@@ -2064,7 +2064,7 @@ impl<'tcx> Operand<'tcx> {
20642064
Operand::Constant(box Constant {
20652065
span,
20662066
user_ty: None,
2067-
literal: ConstantSource::Val(val.into(), ty),
2067+
literal: ConstantKind::Val(val.into(), ty),
20682068
})
20692069
}
20702070

@@ -2406,11 +2406,11 @@ pub struct Constant<'tcx> {
24062406
/// Needed for NLL to impose user-given type constraints.
24072407
pub user_ty: Option<UserTypeAnnotationIndex>,
24082408

2409-
pub literal: ConstantSource<'tcx>,
2409+
pub literal: ConstantKind<'tcx>,
24102410
}
24112411

24122412
#[derive(Clone, Copy, PartialEq, PartialOrd, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
2413-
pub enum ConstantSource<'tcx> {
2413+
pub enum ConstantKind<'tcx> {
24142414
/// This constant came from the type system
24152415
Ty(&'tcx ty::Const<'tcx>),
24162416
/// This constant cannot go back into the type system, as it represents
@@ -2436,33 +2436,33 @@ impl Constant<'tcx> {
24362436
}
24372437
}
24382438

2439-
impl From<&'tcx ty::Const<'tcx>> for ConstantSource<'tcx> {
2439+
impl From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> {
24402440
fn from(ct: &'tcx ty::Const<'tcx>) -> Self {
24412441
Self::Ty(ct)
24422442
}
24432443
}
24442444

2445-
impl ConstantSource<'tcx> {
2445+
impl ConstantKind<'tcx> {
24462446
/// Returns `None` if the constant is not trivially safe for use in the type system.
24472447
pub fn const_for_ty(&self) -> Option<&'tcx ty::Const<'tcx>> {
24482448
match self {
2449-
ConstantSource::Ty(c) => Some(c),
2450-
ConstantSource::Val(..) => None,
2449+
ConstantKind::Ty(c) => Some(c),
2450+
ConstantKind::Val(..) => None,
24512451
}
24522452
}
24532453

24542454
pub fn ty(&self) -> Ty<'tcx> {
24552455
match self {
2456-
ConstantSource::Ty(c) => c.ty,
2457-
ConstantSource::Val(_, ty) => ty,
2456+
ConstantKind::Ty(c) => c.ty,
2457+
ConstantKind::Val(_, ty) => ty,
24582458
}
24592459
}
24602460

24612461
#[inline]
24622462
pub fn try_to_value(self) -> Option<interpret::ConstValue<'tcx>> {
24632463
match self {
2464-
ConstantSource::Ty(c) => c.val.try_to_value(),
2465-
ConstantSource::Val(val, _) => Some(val),
2464+
ConstantKind::Ty(c) => c.val.try_to_value(),
2465+
ConstantKind::Val(val, _) => Some(val),
24662466
}
24672467
}
24682468

@@ -2709,8 +2709,8 @@ impl<'tcx> Display for Constant<'tcx> {
27092709
_ => write!(fmt, "const ")?,
27102710
}
27112711
match self.literal {
2712-
ConstantSource::Ty(c) => pretty_print_const(c, fmt, true),
2713-
ConstantSource::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true),
2712+
ConstantKind::Ty(c) => pretty_print_const(c, fmt, true),
2713+
ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true),
27142714
}
27152715
}
27162716
}

compiler/rustc_middle/src/mir/type_foldable.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,18 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
347347
}
348348
}
349349

350-
impl<'tcx> TypeFoldable<'tcx> for ConstantSource<'tcx> {
350+
impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
351351
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
352352
match self {
353-
ConstantSource::Ty(c) => ConstantSource::Ty(c.fold_with(folder)),
354-
ConstantSource::Val(v, t) => ConstantSource::Val(v, t.fold_with(folder)),
353+
ConstantKind::Ty(c) => ConstantKind::Ty(c.fold_with(folder)),
354+
ConstantKind::Val(v, t) => ConstantKind::Val(v, t.fold_with(folder)),
355355
}
356356
}
357357

358358
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
359359
match *self {
360-
ConstantSource::Ty(c) => c.visit_with(visitor),
361-
ConstantSource::Val(_, t) => t.visit_with(visitor),
360+
ConstantKind::Ty(c) => c.visit_with(visitor),
361+
ConstantKind::Val(_, t) => t.visit_with(visitor),
362362
}
363363
}
364364
}

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,8 @@ macro_rules! make_mir_visitor {
872872
self.visit_span(span);
873873
drop(user_ty); // no visit method for this
874874
match literal {
875-
ConstantSource::Ty(ct) => self.visit_const(ct, location),
876-
ConstantSource::Val(_, t) => self.visit_ty(t, TyContext::Location(location)),
875+
ConstantKind::Ty(ct) => self.visit_const(ct, location),
876+
ConstantKind::Val(_, t) => self.visit_ty(t, TyContext::Location(location)),
877877
}
878878
}
879879

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
315315
} else {
316316
let tcx = self.tcx();
317317
let maybe_uneval = match constant.literal {
318-
ConstantSource::Ty(ct) => match ct.val {
318+
ConstantKind::Ty(ct) => match ct.val {
319319
ty::ConstKind::Unevaluated(def, substs, promoted) => {
320320
Some((def, substs, promoted))
321321
}

compiler/rustc_mir/src/interpret/operand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
573573

574574
crate fn mir_const_to_op(
575575
&self,
576-
val: &mir::ConstantSource<'tcx>,
576+
val: &mir::ConstantKind<'tcx>,
577577
layout: Option<TyAndLayout<'tcx>>,
578578
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
579579
match val {
580-
mir::ConstantSource::Ty(ct) => self.const_to_op(ct, layout),
581-
mir::ConstantSource::Val(val, ty) => self.const_val_to_op(*val, ty, None),
580+
mir::ConstantKind::Ty(ct) => self.const_to_op(ct, layout),
581+
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, ty, None),
582582
}
583583
}
584584

compiler/rustc_mir/src/transform/const_prop.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use rustc_middle::mir::visit::{
1313
MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor,
1414
};
1515
use rustc_middle::mir::{
16-
AssertKind, BasicBlock, BinOp, Body, ClearCrossCrate, Constant, ConstantSource, Local,
17-
LocalDecl, LocalKind, Location, Operand, Place, Rvalue, SourceInfo, SourceScope,
18-
SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE,
16+
AssertKind, BasicBlock, BinOp, Body, ClearCrossCrate, Constant, ConstantKind, Local, LocalDecl,
17+
LocalKind, Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData,
18+
Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE,
1919
};
2020
use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout};
2121
use rustc_middle::ty::subst::{InternalSubsts, Subst};
@@ -489,14 +489,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
489489
let err = ConstEvalErr::new(&self.ecx, error, Some(c.span));
490490
if let Some(lint_root) = self.lint_root(source_info) {
491491
let lint_only = match c.literal {
492-
ConstantSource::Ty(ct) => match ct.val {
492+
ConstantKind::Ty(ct) => match ct.val {
493493
// Promoteds must lint and not error as the user didn't ask for them
494494
ConstKind::Unevaluated(_, _, Some(_)) => true,
495495
// Out of backwards compatibility we cannot report hard errors in unused
496496
// generic functions using associated constants of the generic parameters.
497497
_ => c.literal.needs_subst(),
498498
},
499-
ConstantSource::Val(_, ty) => ty.needs_subst(),
499+
ConstantKind::Val(_, ty) => ty.needs_subst(),
500500
};
501501
if lint_only {
502502
// Out of backwards compatibility we cannot report hard errors in unused
@@ -818,7 +818,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
818818
) {
819819
if let Rvalue::Use(Operand::Constant(c)) = rval {
820820
match c.literal {
821-
ConstantSource::Ty(c) if matches!(c.val, ConstKind::Unevaluated(..)) => {}
821+
ConstantKind::Ty(c) if matches!(c.val, ConstKind::Unevaluated(..)) => {}
822822
_ => {
823823
trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c);
824824
return;

compiler/rustc_mir/src/util/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
450450
self.push(&format!("+ user_ty: {:?}", user_ty));
451451
}
452452
match literal {
453-
ConstantSource::Ty(literal) => self.push(&format!("+ literal: {:?}", literal)),
454-
ConstantSource::Val(val, ty) => {
453+
ConstantKind::Ty(literal) => self.push(&format!("+ literal: {:?}", literal)),
454+
ConstantKind::Val(val, ty) => {
455455
self.push(&format!("+ literal: {:?}, {}", val, ty))
456456
}
457457
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
378378
Ok(self.locals[local])
379379
}
380380
mir::Operand::Constant(ct) => match ct.literal {
381-
mir::ConstantSource::Ty(ct) => Ok(self.add_node(Node::Leaf(ct), span)),
382-
mir::ConstantSource::Val(..) => self.error(Some(span), "unsupported constant")?,
381+
mir::ConstantKind::Ty(ct) => Ok(self.add_node(Node::Leaf(ct), span)),
382+
mir::ConstantKind::Val(..) => self.error(Some(span), "unsupported constant")?,
383383
},
384384
}
385385
}

0 commit comments

Comments
 (0)