about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/abstract_const.rs
blob: 1ef10241143b83ed0ca19f0c51abff8f84ff0419 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! A subset of a mir body used for const evaluatability checking.
use crate::mir::{self, CastKind};
use crate::ty::{self, Ty};

rustc_index::newtype_index! {
    /// An index into an `AbstractConst`.
    pub struct NodeId {
        derive [HashStable]
        DEBUG_FORMAT = "n{}",
    }
}

/// A node of an `AbstractConst`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
pub enum Node<'tcx> {
    Leaf(&'tcx ty::Const<'tcx>),
    Binop(mir::BinOp, NodeId, NodeId),
    UnaryOp(mir::UnOp, NodeId),
    FunctionCall(NodeId, &'tcx [NodeId]),
    Cast(CastKind, NodeId, Ty<'tcx>),
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
pub enum NotConstEvaluatable {
    Error(rustc_errors::ErrorReported),
    MentionsInfer,
    MentionsParam,
}

impl From<rustc_errors::ErrorReported> for NotConstEvaluatable {
    fn from(e: rustc_errors::ErrorReported) -> NotConstEvaluatable {
        NotConstEvaluatable::Error(e)
    }
}

TrivialTypeFoldableAndLiftImpls! {
    NotConstEvaluatable,
}