1
Fork 0

Auto merge of #94059 - b-naber:constantkind-val-transformation, r=lcnr

Treat constant values as mir::ConstantKind::Val

Another step that is necessary for the introduction of Valtrees: we don't want to treat `ty::Const` instances of kind `ty::ConstKind::Value` as `mir::ConstantKind::Ty` anymore.

r? `@oli-obk`
This commit is contained in:
bors 2022-03-10 05:53:59 +00:00
commit d7b282b886
17 changed files with 95 additions and 36 deletions

View file

@ -2,7 +2,7 @@
use crate::build::CFG;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::ty::TyCtxt;
impl<'tcx> CFG<'tcx> {
crate fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
@ -73,7 +73,7 @@ impl<'tcx> CFG<'tcx> {
Rvalue::Use(Operand::Constant(Box::new(Constant {
span: source_info.span,
user_ty: None,
literal: ty::Const::zero_sized(tcx, tcx.types.unit).into(),
literal: ConstantKind::from_zero_sized(tcx.types.unit),
}))),
);
}

View file

@ -9,7 +9,7 @@ use rustc_hir as hir;
use rustc_index::vec::Idx;
use rustc_middle::mir::*;
use rustc_middle::thir::*;
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation};
use rustc_middle::ty::CanonicalUserTypeAnnotation;
use std::iter;
impl<'a, 'tcx> Builder<'a, 'tcx> {
@ -107,7 +107,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant {
span: expr_span,
user_ty: None,
literal: ty::Const::from_bool(this.tcx, true).into(),
literal: ConstantKind::from_bool(this.tcx, true),
},
);
@ -118,7 +118,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant {
span: expr_span,
user_ty: None,
literal: ty::Const::from_bool(this.tcx, false).into(),
literal: ConstantKind::from_bool(this.tcx, false),
},
);
@ -183,8 +183,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span: expr_span,
user_ty: None,
literal: match op {
LogicalOp::And => ty::Const::from_bool(this.tcx, false).into(),
LogicalOp::Or => ty::Const::from_bool(this.tcx, true).into(),
LogicalOp::And => ConstantKind::from_bool(this.tcx, false),
LogicalOp::Or => ConstantKind::from_bool(this.tcx, true),
},
},
);

View file

@ -54,7 +54,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant {
span: source_info.span,
user_ty: None,
literal: ty::Const::from_usize(self.tcx, value).into(),
literal: ConstantKind::from_usize(self.tcx, value),
},
);
temp

View file

@ -569,6 +569,9 @@ impl<'tcx> Cx<'tcx> {
hir::ExprKind::ConstBlock(ref anon_const) => {
let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id);
// FIXME Do we want to use `from_inline_const` once valtrees
// are introduced? This would create `ValTree`s that will never be used...
let value = ty::Const::from_inline_const(self.tcx, anon_const_def_id);
ExprKind::ConstBlock { value }