rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const
This commit is contained in:
parent
a2374e65aa
commit
c94410c145
72 changed files with 430 additions and 449 deletions
|
@ -49,7 +49,7 @@ impl<'tcx> CFG<'tcx> {
|
|||
block: BasicBlock,
|
||||
source_info: SourceInfo,
|
||||
temp: Place<'tcx>,
|
||||
constant: Constant<'tcx>,
|
||||
constant: ConstOperand<'tcx>,
|
||||
) {
|
||||
self.push_assign(
|
||||
block,
|
||||
|
@ -70,10 +70,10 @@ impl<'tcx> CFG<'tcx> {
|
|||
block,
|
||||
source_info,
|
||||
place,
|
||||
Rvalue::Use(Operand::Constant(Box::new(Constant {
|
||||
Rvalue::Use(Operand::Constant(Box::new(ConstOperand {
|
||||
span: source_info.span,
|
||||
user_ty: None,
|
||||
literal: ConstantKind::zero_sized(tcx.types.unit),
|
||||
const_: Const::zero_sized(tcx.types.unit),
|
||||
}))),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -283,12 +283,12 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
|||
ExprKind::StaticRef { alloc_id, ty, .. } => {
|
||||
let const_val =
|
||||
ConstValue::Scalar(Scalar::from_pointer((*alloc_id).into(), &self.tcx));
|
||||
let literal = ConstantKind::Val(const_val, *ty);
|
||||
let const_ = Const::Val(const_val, *ty);
|
||||
|
||||
Ok(Operand::Constant(Box::new(Constant {
|
||||
Ok(Operand::Constant(Box::new(ConstOperand {
|
||||
span: expr.span,
|
||||
user_ty: None,
|
||||
literal
|
||||
const_
|
||||
})))
|
||||
},
|
||||
)
|
||||
|
@ -301,7 +301,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
|||
| ExprKind::NonHirLiteral { .. }
|
||||
| ExprKind::ConstBlock { .. } => Ok({
|
||||
let value = as_constant_inner(expr, |_| None, self.tcx);
|
||||
value.literal.eval_bits(self.tcx, self.param_env)
|
||||
value.const_.eval_bits(self.tcx, self.param_env)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_target::abi::Size;
|
|||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Compile `expr`, yielding a compile-time constant. Assumes that
|
||||
/// `expr` is a valid compile-time constant!
|
||||
pub(crate) fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> {
|
||||
pub(crate) fn as_constant(&mut self, expr: &Expr<'tcx>) -> ConstOperand<'tcx> {
|
||||
let this = self;
|
||||
let tcx = this.tcx;
|
||||
let Expr { ty, temp_lifetime: _, span, ref kind } = *expr;
|
||||
|
@ -42,62 +42,62 @@ pub fn as_constant_inner<'tcx>(
|
|||
expr: &Expr<'tcx>,
|
||||
push_cuta: impl FnMut(&Box<CanonicalUserType<'tcx>>) -> Option<UserTypeAnnotationIndex>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> Constant<'tcx> {
|
||||
) -> ConstOperand<'tcx> {
|
||||
let Expr { ty, temp_lifetime: _, span, ref kind } = *expr;
|
||||
match *kind {
|
||||
ExprKind::Literal { lit, neg } => {
|
||||
let literal =
|
||||
match lit_to_mir_constant(tcx, LitToConstInput { lit: &lit.node, ty, neg }) {
|
||||
Ok(c) => c,
|
||||
Err(LitToConstError::Reported(guar)) => {
|
||||
ConstantKind::Ty(ty::Const::new_error(tcx, guar, ty))
|
||||
}
|
||||
Err(LitToConstError::TypeError) => {
|
||||
bug!("encountered type error in `lit_to_mir_constant`")
|
||||
}
|
||||
};
|
||||
let const_ = match lit_to_mir_constant(tcx, LitToConstInput { lit: &lit.node, ty, neg })
|
||||
{
|
||||
Ok(c) => c,
|
||||
Err(LitToConstError::Reported(guar)) => {
|
||||
Const::Ty(ty::Const::new_error(tcx, guar, ty))
|
||||
}
|
||||
Err(LitToConstError::TypeError) => {
|
||||
bug!("encountered type error in `lit_to_mir_constant`")
|
||||
}
|
||||
};
|
||||
|
||||
Constant { span, user_ty: None, literal }
|
||||
ConstOperand { span, user_ty: None, const_ }
|
||||
}
|
||||
ExprKind::NonHirLiteral { lit, ref user_ty } => {
|
||||
let user_ty = user_ty.as_ref().and_then(push_cuta);
|
||||
|
||||
let literal = ConstantKind::Val(ConstValue::Scalar(Scalar::Int(lit)), ty);
|
||||
let const_ = Const::Val(ConstValue::Scalar(Scalar::Int(lit)), ty);
|
||||
|
||||
Constant { span, user_ty, literal }
|
||||
ConstOperand { span, user_ty, const_ }
|
||||
}
|
||||
ExprKind::ZstLiteral { ref user_ty } => {
|
||||
let user_ty = user_ty.as_ref().and_then(push_cuta);
|
||||
|
||||
let literal = ConstantKind::Val(ConstValue::ZeroSized, ty);
|
||||
let const_ = Const::Val(ConstValue::ZeroSized, ty);
|
||||
|
||||
Constant { span, user_ty, literal }
|
||||
ConstOperand { span, user_ty, const_ }
|
||||
}
|
||||
ExprKind::NamedConst { def_id, args, ref user_ty } => {
|
||||
let user_ty = user_ty.as_ref().and_then(push_cuta);
|
||||
|
||||
let uneval = mir::UnevaluatedConst::new(def_id, args);
|
||||
let literal = ConstantKind::Unevaluated(uneval, ty);
|
||||
let const_ = Const::Unevaluated(uneval, ty);
|
||||
|
||||
Constant { user_ty, span, literal }
|
||||
ConstOperand { user_ty, span, const_ }
|
||||
}
|
||||
ExprKind::ConstParam { param, def_id: _ } => {
|
||||
let const_param = ty::Const::new_param(tcx, param, expr.ty);
|
||||
let literal = ConstantKind::Ty(const_param);
|
||||
let const_ = Const::Ty(const_param);
|
||||
|
||||
Constant { user_ty: None, span, literal }
|
||||
ConstOperand { user_ty: None, span, const_ }
|
||||
}
|
||||
ExprKind::ConstBlock { did: def_id, args } => {
|
||||
let uneval = mir::UnevaluatedConst::new(def_id, args);
|
||||
let literal = ConstantKind::Unevaluated(uneval, ty);
|
||||
let const_ = Const::Unevaluated(uneval, ty);
|
||||
|
||||
Constant { user_ty: None, span, literal }
|
||||
ConstOperand { user_ty: None, span, const_ }
|
||||
}
|
||||
ExprKind::StaticRef { alloc_id, ty, .. } => {
|
||||
let const_val = ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &tcx));
|
||||
let literal = ConstantKind::Val(const_val, ty);
|
||||
let const_ = Const::Val(const_val, ty);
|
||||
|
||||
Constant { span, user_ty: None, literal }
|
||||
ConstOperand { span, user_ty: None, const_ }
|
||||
}
|
||||
_ => span_bug!(span, "expression is not a valid constant {:?}", kind),
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ pub fn as_constant_inner<'tcx>(
|
|||
fn lit_to_mir_constant<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
lit_input: LitToConstInput<'tcx>,
|
||||
) -> Result<ConstantKind<'tcx>, LitToConstError> {
|
||||
) -> Result<Const<'tcx>, LitToConstError> {
|
||||
let LitToConstInput { lit, ty, neg } = lit_input;
|
||||
let trunc = |n| {
|
||||
let param_ty = ty::ParamEnv::reveal_all().and(ty);
|
||||
|
@ -173,5 +173,5 @@ fn lit_to_mir_constant<'tcx>(
|
|||
_ => return Err(LitToConstError::TypeError),
|
||||
};
|
||||
|
||||
Ok(ConstantKind::Val(value, ty))
|
||||
Ok(Const::Val(value, ty))
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
let mut comparer = |range: u128, bin_op: BinOp| -> Place<'tcx> {
|
||||
let range_val =
|
||||
ConstantKind::from_bits(this.tcx, range, ty::ParamEnv::empty().and(unsigned_ty));
|
||||
Const::from_bits(this.tcx, range, ty::ParamEnv::empty().and(unsigned_ty));
|
||||
let lit_op = this.literal_operand(expr.span, range_val);
|
||||
let is_bin_op = this.temp(bool_ty, expr_span);
|
||||
this.cfg.push_assign(
|
||||
|
@ -485,10 +485,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
|
||||
block = unpack!(this.stmt_expr(block, expr, None));
|
||||
block.and(Rvalue::Use(Operand::Constant(Box::new(Constant {
|
||||
block.and(Rvalue::Use(Operand::Constant(Box::new(ConstOperand {
|
||||
span: expr_span,
|
||||
user_ty: None,
|
||||
literal: ConstantKind::zero_sized(this.tcx.types.unit),
|
||||
const_: Const::zero_sized(this.tcx.types.unit),
|
||||
}))))
|
||||
}
|
||||
|
||||
|
@ -817,7 +817,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
fn neg_1_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
||||
let param_ty = ty::ParamEnv::empty().and(ty);
|
||||
let size = self.tcx.layout_of(param_ty).unwrap().size;
|
||||
let literal = ConstantKind::from_bits(self.tcx, size.unsigned_int_max(), param_ty);
|
||||
let literal = Const::from_bits(self.tcx, size.unsigned_int_max(), param_ty);
|
||||
|
||||
self.literal_operand(span, literal)
|
||||
}
|
||||
|
@ -828,7 +828,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let param_ty = ty::ParamEnv::empty().and(ty);
|
||||
let bits = self.tcx.layout_of(param_ty).unwrap().size.bits();
|
||||
let n = 1 << (bits - 1);
|
||||
let literal = ConstantKind::from_bits(self.tcx, n, param_ty);
|
||||
let literal = Const::from_bits(self.tcx, n, param_ty);
|
||||
|
||||
self.literal_operand(span, literal)
|
||||
}
|
||||
|
|
|
@ -114,10 +114,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
true_block,
|
||||
source_info,
|
||||
destination,
|
||||
Constant {
|
||||
ConstOperand {
|
||||
span: expr_span,
|
||||
user_ty: None,
|
||||
literal: ConstantKind::from_bool(this.tcx, true),
|
||||
const_: Const::from_bool(this.tcx, true),
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -125,10 +125,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
false_block,
|
||||
source_info,
|
||||
destination,
|
||||
Constant {
|
||||
ConstOperand {
|
||||
span: expr_span,
|
||||
user_ty: None,
|
||||
literal: ConstantKind::from_bool(this.tcx, false),
|
||||
const_: Const::from_bool(this.tcx, false),
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -186,10 +186,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
short_circuit,
|
||||
source_info,
|
||||
destination,
|
||||
Constant {
|
||||
ConstOperand {
|
||||
span: expr.span,
|
||||
user_ty: None,
|
||||
literal: ConstantKind::from_bool(this.tcx, constant),
|
||||
const_: Const::from_bool(this.tcx, constant),
|
||||
},
|
||||
);
|
||||
let rhs = unpack!(this.expr_into_dest(destination, continuation, &this.thir[rhs]));
|
||||
|
@ -433,12 +433,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
thir::InlineAsmOperand::Const { value, span } => {
|
||||
mir::InlineAsmOperand::Const {
|
||||
value: Box::new(Constant { span, user_ty: None, literal: value }),
|
||||
value: Box::new(ConstOperand {
|
||||
span,
|
||||
user_ty: None,
|
||||
const_: value,
|
||||
}),
|
||||
}
|
||||
}
|
||||
thir::InlineAsmOperand::SymFn { value, span } => {
|
||||
mir::InlineAsmOperand::SymFn {
|
||||
value: Box::new(Constant { span, user_ty: None, literal: value }),
|
||||
value: Box::new(ConstOperand {
|
||||
span,
|
||||
user_ty: None,
|
||||
const_: value,
|
||||
}),
|
||||
}
|
||||
}
|
||||
thir::InlineAsmOperand::SymStatic { def_id } => {
|
||||
|
|
|
@ -1005,13 +1005,13 @@ enum TestKind<'tcx> {
|
|||
///
|
||||
/// For `bool` we always generate two edges, one for `true` and one for
|
||||
/// `false`.
|
||||
options: FxIndexMap<ConstantKind<'tcx>, u128>,
|
||||
options: FxIndexMap<Const<'tcx>, u128>,
|
||||
},
|
||||
|
||||
/// Test for equality with value, possibly after an unsizing coercion to
|
||||
/// `ty`,
|
||||
Eq {
|
||||
value: ConstantKind<'tcx>,
|
||||
value: Const<'tcx>,
|
||||
// Integer types are handled by `SwitchInt`, and constants with ADT
|
||||
// types are converted back into patterns, so this can only be `&str`,
|
||||
// `&[T]`, `f32` or `f64`.
|
||||
|
|
|
@ -85,7 +85,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
&mut self,
|
||||
test_place: &PlaceBuilder<'tcx>,
|
||||
candidate: &Candidate<'pat, 'tcx>,
|
||||
options: &mut FxIndexMap<ConstantKind<'tcx>, u128>,
|
||||
options: &mut FxIndexMap<Const<'tcx>, u128>,
|
||||
) -> bool {
|
||||
let Some(match_pair) = candidate.match_pairs.iter().find(|mp| mp.place == *test_place)
|
||||
else {
|
||||
|
@ -252,10 +252,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
source_info,
|
||||
TerminatorKind::Call {
|
||||
func: Operand::Constant(Box::new(Constant {
|
||||
func: Operand::Constant(Box::new(ConstOperand {
|
||||
span: test.span,
|
||||
user_ty: None,
|
||||
literal: method,
|
||||
const_: method,
|
||||
})),
|
||||
args: vec![Operand::Move(ref_string)],
|
||||
destination: ref_str,
|
||||
|
@ -385,7 +385,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block: BasicBlock,
|
||||
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
|
||||
source_info: SourceInfo,
|
||||
value: ConstantKind<'tcx>,
|
||||
value: Const<'tcx>,
|
||||
mut val: Place<'tcx>,
|
||||
mut ty: Ty<'tcx>,
|
||||
) {
|
||||
|
@ -482,7 +482,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
source_info,
|
||||
TerminatorKind::Call {
|
||||
func: Operand::Constant(Box::new(Constant {
|
||||
func: Operand::Constant(Box::new(ConstOperand {
|
||||
span: source_info.span,
|
||||
|
||||
// FIXME(#54571): This constant comes from user input (a
|
||||
|
@ -491,7 +491,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// Need to experiment.
|
||||
user_ty: None,
|
||||
|
||||
literal: method,
|
||||
const_: method,
|
||||
})),
|
||||
args: vec![Operand::Copy(val), expect],
|
||||
destination: eq_result,
|
||||
|
@ -797,11 +797,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
span_bug!(match_pair.pattern.span, "simplifiable pattern found: {:?}", match_pair.pattern)
|
||||
}
|
||||
|
||||
fn const_range_contains(
|
||||
&self,
|
||||
range: &PatRange<'tcx>,
|
||||
value: ConstantKind<'tcx>,
|
||||
) -> Option<bool> {
|
||||
fn const_range_contains(&self, range: &PatRange<'tcx>, value: Const<'tcx>) -> Option<bool> {
|
||||
use std::cmp::Ordering::*;
|
||||
|
||||
// For performance, it's important to only do the second
|
||||
|
@ -818,7 +814,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
fn values_not_contained_in_range(
|
||||
&self,
|
||||
range: &PatRange<'tcx>,
|
||||
options: &FxIndexMap<ConstantKind<'tcx>, u128>,
|
||||
options: &FxIndexMap<Const<'tcx>, u128>,
|
||||
) -> Option<bool> {
|
||||
for &val in options.keys() {
|
||||
if self.const_range_contains(range, val)? {
|
||||
|
@ -863,7 +859,7 @@ fn trait_method<'tcx>(
|
|||
trait_def_id: DefId,
|
||||
method_name: Symbol,
|
||||
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
) -> ConstantKind<'tcx> {
|
||||
) -> Const<'tcx> {
|
||||
// The unhygienic comparison here is acceptable because this is only
|
||||
// used on known traits.
|
||||
let item = tcx
|
||||
|
@ -874,5 +870,5 @@ fn trait_method<'tcx>(
|
|||
|
||||
let method_ty = Ty::new_fn_def(tcx, item.def_id, args);
|
||||
|
||||
ConstantKind::zero_sized(method_ty)
|
||||
Const::zero_sized(method_ty)
|
||||
}
|
||||
|
|
|
@ -25,19 +25,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
/// Convenience function for creating a literal operand, one
|
||||
/// without any user type annotation.
|
||||
pub(crate) fn literal_operand(
|
||||
&mut self,
|
||||
span: Span,
|
||||
literal: ConstantKind<'tcx>,
|
||||
) -> Operand<'tcx> {
|
||||
let constant = Box::new(Constant { span, user_ty: None, literal });
|
||||
pub(crate) fn literal_operand(&mut self, span: Span, const_: Const<'tcx>) -> Operand<'tcx> {
|
||||
let constant = Box::new(ConstOperand { span, user_ty: None, const_ });
|
||||
Operand::Constant(constant)
|
||||
}
|
||||
|
||||
/// Returns a zero literal operand for the appropriate type, works for
|
||||
/// bool, char and integers.
|
||||
pub(crate) fn zero_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
||||
let literal = ConstantKind::from_bits(self.tcx, 0, ty::ParamEnv::empty().and(ty));
|
||||
let literal = Const::from_bits(self.tcx, 0, ty::ParamEnv::empty().and(ty));
|
||||
|
||||
self.literal_operand(span, literal)
|
||||
}
|
||||
|
@ -54,10 +50,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
source_info,
|
||||
temp,
|
||||
Constant {
|
||||
ConstOperand {
|
||||
span: source_info.span,
|
||||
user_ty: None,
|
||||
literal: ConstantKind::from_usize(self.tcx, value),
|
||||
const_: Const::from_usize(self.tcx, value),
|
||||
},
|
||||
);
|
||||
temp
|
||||
|
|
|
@ -647,21 +647,15 @@ impl<'tcx> Cx<'tcx> {
|
|||
out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
|
||||
},
|
||||
hir::InlineAsmOperand::Const { ref anon_const } => {
|
||||
let value = mir::ConstantKind::from_anon_const(
|
||||
tcx,
|
||||
anon_const.def_id,
|
||||
self.param_env,
|
||||
);
|
||||
let value =
|
||||
mir::Const::from_anon_const(tcx, anon_const.def_id, self.param_env);
|
||||
let span = tcx.def_span(anon_const.def_id);
|
||||
|
||||
InlineAsmOperand::Const { value, span }
|
||||
}
|
||||
hir::InlineAsmOperand::SymFn { ref anon_const } => {
|
||||
let value = mir::ConstantKind::from_anon_const(
|
||||
tcx,
|
||||
anon_const.def_id,
|
||||
self.param_env,
|
||||
);
|
||||
let value =
|
||||
mir::Const::from_anon_const(tcx, anon_const.def_id, self.param_env);
|
||||
let span = tcx.def_span(anon_const.def_id);
|
||||
|
||||
InlineAsmOperand::SymFn { value, span }
|
||||
|
|
|
@ -27,7 +27,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
#[instrument(level = "debug", skip(self), ret)]
|
||||
pub(super) fn const_to_pat(
|
||||
&self,
|
||||
cv: mir::ConstantKind<'tcx>,
|
||||
cv: mir::Const<'tcx>,
|
||||
id: hir::HirId,
|
||||
span: Span,
|
||||
check_body_for_struct_match_violation: Option<DefId>,
|
||||
|
@ -104,7 +104,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
|
||||
fn to_pat(
|
||||
&mut self,
|
||||
cv: mir::ConstantKind<'tcx>,
|
||||
cv: mir::Const<'tcx>,
|
||||
check_body_for_struct_match_violation: Option<DefId>,
|
||||
) -> Box<Pat<'tcx>> {
|
||||
trace!(self.treat_byte_string_as_slice);
|
||||
|
@ -124,7 +124,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
debug!(?check_body_for_struct_match_violation, ?mir_structural_match_violation);
|
||||
|
||||
let inlined_const_as_pat = match cv {
|
||||
mir::ConstantKind::Ty(c) => match c.kind() {
|
||||
mir::Const::Ty(c) => match c.kind() {
|
||||
ty::ConstKind::Param(_)
|
||||
| ty::ConstKind::Infer(_)
|
||||
| ty::ConstKind::Bound(_, _)
|
||||
|
@ -144,10 +144,10 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
})
|
||||
}),
|
||||
},
|
||||
mir::ConstantKind::Unevaluated(_, _) => {
|
||||
mir::Const::Unevaluated(_, _) => {
|
||||
span_bug!(self.span, "unevaluated const in `to_pat`: {cv:?}")
|
||||
}
|
||||
mir::ConstantKind::Val(_, _) => Box::new(Pat {
|
||||
mir::Const::Val(_, _) => Box::new(Pat {
|
||||
span: self.span,
|
||||
ty: cv.ty(),
|
||||
kind: PatKind::Constant { value: cv },
|
||||
|
@ -385,9 +385,9 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
ty::Ref(_, pointee_ty, ..) => match *pointee_ty.kind() {
|
||||
// `&str` is represented as a valtree, let's keep using this
|
||||
// optimization for now.
|
||||
ty::Str => PatKind::Constant {
|
||||
value: mir::ConstantKind::Ty(ty::Const::new_value(tcx, cv, ty)),
|
||||
},
|
||||
ty::Str => {
|
||||
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_value(tcx, cv, ty)) }
|
||||
}
|
||||
// Backwards compatibility hack: support references to non-structural types,
|
||||
// but hard error if we aren't behind a double reference. We could just use
|
||||
// the fallback code path below, but that would allow *more* of this fishy
|
||||
|
@ -445,9 +445,9 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
}
|
||||
}
|
||||
},
|
||||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => PatKind::Constant {
|
||||
value: mir::ConstantKind::Ty(ty::Const::new_value(tcx, cv, ty)),
|
||||
},
|
||||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => {
|
||||
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_value(tcx, cv, ty)) }
|
||||
}
|
||||
ty::FnPtr(..) | ty::RawPtr(..) => unreachable!(),
|
||||
_ => {
|
||||
self.saw_const_match_error.set(true);
|
||||
|
|
|
@ -137,12 +137,12 @@ impl IntRange {
|
|||
fn from_constant<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: mir::ConstantKind<'tcx>,
|
||||
value: mir::Const<'tcx>,
|
||||
) -> Option<IntRange> {
|
||||
let ty = value.ty();
|
||||
let (target_size, bias) = Self::integral_size_and_signed_bias(tcx, ty)?;
|
||||
let val = match value {
|
||||
mir::ConstantKind::Ty(c) if let ty::ConstKind::Value(valtree) = c.kind() => {
|
||||
mir::Const::Ty(c) if let ty::ConstKind::Value(valtree) = c.kind() => {
|
||||
valtree.unwrap_leaf().to_bits(target_size).ok()
|
||||
},
|
||||
// This is a more general form of the previous case.
|
||||
|
@ -225,8 +225,8 @@ impl IntRange {
|
|||
let (lo, hi) = (lo ^ bias, hi ^ bias);
|
||||
|
||||
let env = ty::ParamEnv::empty().and(ty);
|
||||
let lo_const = mir::ConstantKind::from_bits(tcx, lo, env);
|
||||
let hi_const = mir::ConstantKind::from_bits(tcx, hi, env);
|
||||
let lo_const = mir::Const::from_bits(tcx, lo, env);
|
||||
let hi_const = mir::Const::from_bits(tcx, hi, env);
|
||||
|
||||
let kind = if lo == hi {
|
||||
PatKind::Constant { value: lo_const }
|
||||
|
@ -619,9 +619,9 @@ pub(super) enum Constructor<'tcx> {
|
|||
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
|
||||
IntRange(IntRange),
|
||||
/// Ranges of floating-point literal values (`2.0..=5.2`).
|
||||
FloatRange(mir::ConstantKind<'tcx>, mir::ConstantKind<'tcx>, RangeEnd),
|
||||
FloatRange(mir::Const<'tcx>, mir::Const<'tcx>, RangeEnd),
|
||||
/// String literals. Strings are not quite the same as `&[u8]` so we treat them separately.
|
||||
Str(mir::ConstantKind<'tcx>),
|
||||
Str(mir::Const<'tcx>),
|
||||
/// Array and slice patterns.
|
||||
Slice(Slice),
|
||||
/// Constants that must not be matched structurally. They are treated as black
|
||||
|
|
|
@ -20,7 +20,7 @@ use rustc_index::Idx;
|
|||
use rustc_middle::mir::interpret::{
|
||||
ErrorHandled, GlobalId, LitToConstError, LitToConstInput, Scalar,
|
||||
};
|
||||
use rustc_middle::mir::{self, ConstantKind, UserTypeProjection};
|
||||
use rustc_middle::mir::{self, Const, UserTypeProjection};
|
||||
use rustc_middle::mir::{BorrowKind, Mutability};
|
||||
use rustc_middle::thir::{Ascription, BindingMode, FieldPat, LocalVarId, Pat, PatKind, PatRange};
|
||||
use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
||||
|
@ -100,8 +100,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
fn lower_pattern_range(
|
||||
&mut self,
|
||||
ty: Ty<'tcx>,
|
||||
lo: mir::ConstantKind<'tcx>,
|
||||
hi: mir::ConstantKind<'tcx>,
|
||||
lo: mir::Const<'tcx>,
|
||||
hi: mir::Const<'tcx>,
|
||||
end: RangeEnd,
|
||||
span: Span,
|
||||
lo_expr: Option<&hir::Expr<'tcx>>,
|
||||
|
@ -191,18 +191,18 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
lo: Option<&PatKind<'tcx>>,
|
||||
hi: Option<&PatKind<'tcx>>,
|
||||
) -> Option<(mir::ConstantKind<'tcx>, mir::ConstantKind<'tcx>)> {
|
||||
) -> Option<(mir::Const<'tcx>, mir::Const<'tcx>)> {
|
||||
match (lo, hi) {
|
||||
(Some(PatKind::Constant { value: lo }), Some(PatKind::Constant { value: hi })) => {
|
||||
Some((*lo, *hi))
|
||||
}
|
||||
(Some(PatKind::Constant { value: lo }), None) => {
|
||||
let hi = ty.numeric_max_val(self.tcx)?;
|
||||
Some((*lo, mir::ConstantKind::from_ty_const(hi, self.tcx)))
|
||||
Some((*lo, mir::Const::from_ty_const(hi, self.tcx)))
|
||||
}
|
||||
(None, Some(PatKind::Constant { value: hi })) => {
|
||||
let lo = ty.numeric_min_val(self.tcx)?;
|
||||
Some((mir::ConstantKind::from_ty_const(lo, self.tcx), *hi))
|
||||
Some((mir::Const::from_ty_const(lo, self.tcx), *hi))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
@ -525,8 +525,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
.tcx
|
||||
.const_eval_global_id_for_typeck(param_env_reveal_all, cid, Some(span))
|
||||
.map(|val| match val {
|
||||
Some(valtree) => mir::ConstantKind::Ty(ty::Const::new_value(self.tcx, valtree, ty)),
|
||||
None => mir::ConstantKind::Val(
|
||||
Some(valtree) => mir::Const::Ty(ty::Const::new_value(self.tcx, valtree, ty)),
|
||||
None => mir::Const::Val(
|
||||
self.tcx
|
||||
.const_eval_global_id(param_env_reveal_all, cid, Some(span))
|
||||
.expect("const_eval_global_id_for_typeck should have already failed"),
|
||||
|
@ -608,7 +608,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
};
|
||||
if let Some(lit_input) = lit_input {
|
||||
match tcx.at(expr.span).lit_to_const(lit_input) {
|
||||
Ok(c) => return self.const_to_pat(ConstantKind::Ty(c), id, span, None).kind,
|
||||
Ok(c) => return self.const_to_pat(Const::Ty(c), id, span, None).kind,
|
||||
// If an error occurred, ignore that it's a literal
|
||||
// and leave reporting the error up to const eval of
|
||||
// the unevaluated constant below.
|
||||
|
@ -632,7 +632,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
self.tcx.const_eval_resolve_for_typeck(self.param_env, ct, Some(span))
|
||||
{
|
||||
self.const_to_pat(
|
||||
ConstantKind::Ty(ty::Const::new_value(self.tcx, valtree, ty)),
|
||||
Const::Ty(ty::Const::new_value(self.tcx, valtree, ty)),
|
||||
id,
|
||||
span,
|
||||
None,
|
||||
|
@ -641,7 +641,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
} else {
|
||||
// If that fails, convert it to an opaque constant pattern.
|
||||
match tcx.const_eval_resolve(self.param_env, uneval, Some(span)) {
|
||||
Ok(val) => self.const_to_pat(mir::ConstantKind::Val(val, ty), id, span, None).kind,
|
||||
Ok(val) => self.const_to_pat(mir::Const::Val(val, ty), id, span, None).kind,
|
||||
Err(ErrorHandled::TooGeneric(_)) => {
|
||||
// If we land here it means the const can't be evaluated because it's `TooGeneric`.
|
||||
self.tcx.sess.emit_err(ConstPatternDependsOnGenericParameter { span });
|
||||
|
@ -678,7 +678,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
LitToConstInput { lit: &lit.node, ty: self.typeck_results.expr_ty(expr), neg };
|
||||
match self.tcx.at(expr.span).lit_to_const(lit_input) {
|
||||
Ok(constant) => {
|
||||
self.const_to_pat(ConstantKind::Ty(constant), expr.hir_id, lit.span, None).kind
|
||||
self.const_to_pat(Const::Ty(constant), expr.hir_id, lit.span, None).kind
|
||||
}
|
||||
Err(LitToConstError::Reported(_)) => PatKind::Wild,
|
||||
Err(LitToConstError::TypeError) => bug!("lower_lit: had type error"),
|
||||
|
@ -838,8 +838,8 @@ impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> {
|
|||
#[instrument(skip(tcx), level = "debug")]
|
||||
pub(crate) fn compare_const_vals<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
a: mir::ConstantKind<'tcx>,
|
||||
b: mir::ConstantKind<'tcx>,
|
||||
a: mir::Const<'tcx>,
|
||||
b: mir::Const<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> Option<Ordering> {
|
||||
assert_eq!(a.ty(), b.ty());
|
||||
|
@ -855,10 +855,10 @@ pub(crate) fn compare_const_vals<'tcx>(
|
|||
ty::Float(_) | ty::Int(_) => {} // require special handling, see below
|
||||
_ => match (a, b) {
|
||||
(
|
||||
mir::ConstantKind::Val(mir::ConstValue::Scalar(Scalar::Int(a)), _a_ty),
|
||||
mir::ConstantKind::Val(mir::ConstValue::Scalar(Scalar::Int(b)), _b_ty),
|
||||
mir::Const::Val(mir::ConstValue::Scalar(Scalar::Int(a)), _a_ty),
|
||||
mir::Const::Val(mir::ConstValue::Scalar(Scalar::Int(b)), _b_ty),
|
||||
) => return Some(a.cmp(&b)),
|
||||
(mir::ConstantKind::Ty(a), mir::ConstantKind::Ty(b)) => {
|
||||
(mir::Const::Ty(a), mir::Const::Ty(b)) => {
|
||||
return Some(a.kind().cmp(&b.kind()));
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue