Expand description
A simple const eval API, for use on arbitrary HIR expressions.
This cannot use rustcβs const eval, aka miri, as arbitrary HIR expressions cannot be lowered to executable MIR bodies, so we have to do this instead.
Re-exportsΒ§
use crate::res::MaybeDef as _;πuse crate::source::SpanExt as _;πuse crate::source::walk_span_to_context;πuse crate::clip;πuse crate::is_direct_expn_of;πuse crate::sext;πuse crate::sym;πuse crate::unsext;πuse rustc_abi::Size;πuse rustc_apfloat::Float as _;πuse rustc_apfloat::ieee::Half;πuse rustc_apfloat::ieee::Quad;πuse rustc_ast::ast::LitFloatType;πuse rustc_ast::ast::LitKind;πuse rustc_hir::def::DefKind;πuse rustc_hir::def::Res;πuse rustc_hir::BinOpKind;πuse rustc_hir::Block;πuse rustc_hir::ConstArgKind;πuse rustc_hir::ConstBlock;πuse rustc_hir::ConstItemRhs;πuse rustc_hir::Expr;πuse rustc_hir::ExprKind;πuse rustc_hir::HirId;πuse rustc_hir::PatExpr;πuse rustc_hir::PatExprKind;πuse rustc_hir::QPath;πuse rustc_hir::TyKind;πuse rustc_hir::UnOp;πuse rustc_lexer::FrontmatterAllowed;πuse rustc_lexer::tokenize;πuse rustc_lint::LateContext;πuse rustc_middle::mir::interpret::Scalar;πuse rustc_middle::mir::interpret::alloc_range;πuse rustc_middle::mir;πuse rustc_middle::mir::ConstValue;πuse rustc_middle::ty;πuse rustc_middle::ty::FloatTy;πuse rustc_middle::ty::IntTy;πuse rustc_middle::ty::ScalarInt;πuse rustc_middle::ty::Ty;πuse rustc_middle::ty::TyCtxt;πuse rustc_middle::ty::TypeckResults;πuse rustc_middle::ty::UintTy;πuse rustc_span::Symbol;πuse rustc_span::SyntaxContext;πuse rustc_span::bug;πuse rustc_span::span_bug;πuse std::cell::Cell;πuse std::cmp::Ordering;πuse std::hash::Hash;πuse std::hash::Hash;πuse std::hash::Hasher;πuse std::iter;π
StructsΒ§
- Const
Eval Ctxt - The context required to evaluate a constant expression.
EnumsΒ§
- Constant
- A
LitKind-like enum to fold constantExprs into. - Constant
Source - The source of a constant value.
- FullInt
- An integer type (signed or unsigned) with enough bits to represent any integer that can be represented in Rust.
TraitsΒ§
- IntType
Bounds π
FunctionsΒ§
- const_
item_ rhs_ to_ expr - Extracts the [
Expr] backing a const itemβs right-hand side, if it has one. - eval_
int - Evaluates an expression if itβs a builtin integer type.
- field_
of_ πstruct - integer_
const - If
exprevaluates to an integer constant, return its value. - is_
zero_ integer_ const - Check if
exprevaluates to an integer constant of 0. - lit_
to_ mir_ constant - Parses a
LitKindto aConstant. - mir_
to_ const - Converts a [
ConstValue] to aConstant, if possible.