1 //! A subset of a mir body used for const evaluatability checking.
3 use crate::ty::{self, Ty, TyCtxt};
4 use rustc_errors::ErrorGuaranteed;
6 rustc_index::newtype_index! {
7 /// An index into an `AbstractConst`.
14 #[derive(Debug, Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
16 /// thir::ExprKind::As
18 /// thir::ExprKind::Use
22 /// A node of an `AbstractConst`.
23 #[derive(Debug, Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
25 Leaf(ty::Const<'tcx>),
26 Binop(mir::BinOp, NodeId, NodeId),
27 UnaryOp(mir::UnOp, NodeId),
28 FunctionCall(NodeId, &'tcx [NodeId]),
29 Cast(CastKind, NodeId, Ty<'tcx>),
32 #[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
33 pub enum NotConstEvaluatable {
34 Error(ErrorGuaranteed),
39 impl From<ErrorGuaranteed> for NotConstEvaluatable {
40 fn from(e: ErrorGuaranteed) -> NotConstEvaluatable {
41 NotConstEvaluatable::Error(e)
45 TrivialTypeFoldableAndLiftImpls! {
49 impl<'tcx> TyCtxt<'tcx> {
51 pub fn thir_abstract_const_opt_const_arg(
53 def: ty::WithOptConstParam<rustc_hir::def_id::DefId>,
54 ) -> Result<Option<&'tcx [Node<'tcx>]>, ErrorGuaranteed> {
55 if let Some((did, param_did)) = def.as_const_arg() {
56 self.thir_abstract_const_of_const_arg((did, param_did))
58 self.thir_abstract_const(def.did)