use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::infer::canonical::Canonical;
use rustc_middle::middle::region;
use rustc_middle::mir::{BinOp, BorrowKind, FakeReadCause, Field, UnOp};
use rustc_middle::ty::adjustment::PointerCast;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{AdtDef, Const, Ty, UpvarSubsts, UserType};
use rustc_span::Span;
use rustc_target::abi::VariantIdx;
use rustc_target::asm::InlineAsmRegOrRegClass;
crate mod constant;
crate mod cx;
pub use cx::build_thir;
crate mod pattern;
pub use self::pattern::{Ascription, BindingMode, FieldPat, Pat, PatKind, PatRange, PatTyProj};
mod arena;
pub use arena::Arena;
mod util;
#[derive(Copy, Clone, Debug)]
pub enum LintLevel {
Inherited,
Explicit(hir::HirId),
}
#[derive(Debug)]
pub struct Block<'thir, 'tcx> {
pub targeted_by_break: bool,
pub region_scope: region::Scope,
pub opt_destruction_scope: Option<region::Scope>,
pub span: Span,
pub stmts: &'thir [Stmt<'thir, 'tcx>],
pub expr: Option<&'thir Expr<'thir, 'tcx>>,
pub safety_mode: BlockSafety,
}
#[derive(Copy, Clone, Debug)]
pub enum BlockSafety {
Safe,
ExplicitUnsafe(hir::HirId),
PushUnsafe,
PopUnsafe,
}
#[derive(Debug)]
pub struct Stmt<'thir, 'tcx> {
pub kind: StmtKind<'thir, 'tcx>,
pub opt_destruction_scope: Option<region::Scope>,
}
#[derive(Debug)]
pub enum StmtKind<'thir, 'tcx> {
Expr {
scope: region::Scope,
expr: &'thir Expr<'thir, 'tcx>,
},
Let {
remainder_scope: region::Scope,
init_scope: region::Scope,
pattern: Pat<'tcx>,
initializer: Option<&'thir Expr<'thir, 'tcx>>,
lint_level: LintLevel,
},
}
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Expr<'_, '_>, 144);
#[derive(Debug)]
pub struct Expr<'thir, 'tcx> {
pub ty: Ty<'tcx>,
pub temp_lifetime: Option<region::Scope>,
pub span: Span,
pub kind: ExprKind<'thir, 'tcx>,
}
#[derive(Debug)]
pub enum ExprKind<'thir, 'tcx> {
Scope {
region_scope: region::Scope,
lint_level: LintLevel,
value: &'thir Expr<'thir, 'tcx>,
},
Box {
value: &'thir Expr<'thir, 'tcx>,
},
If {
cond: &'thir Expr<'thir, 'tcx>,
then: &'thir Expr<'thir, 'tcx>,
else_opt: Option<&'thir Expr<'thir, 'tcx>>,
},
Call {
ty: Ty<'tcx>,
fun: &'thir Expr<'thir, 'tcx>,
args: &'thir [Expr<'thir, 'tcx>],
from_hir_call: bool,
fn_span: Span,
},
Deref {
arg: &'thir Expr<'thir, 'tcx>,
},
Binary {
op: BinOp,
lhs: &'thir Expr<'thir, 'tcx>,
rhs: &'thir Expr<'thir, 'tcx>,
},
LogicalOp {
op: LogicalOp,
lhs: &'thir Expr<'thir, 'tcx>,
rhs: &'thir Expr<'thir, 'tcx>,
},
Unary {
op: UnOp,
arg: &'thir Expr<'thir, 'tcx>,
},
Cast {
source: &'thir Expr<'thir, 'tcx>,
},
Use {
source: &'thir Expr<'thir, 'tcx>,
},
NeverToAny {
source: &'thir Expr<'thir, 'tcx>,
},
Pointer {
cast: PointerCast,
source: &'thir Expr<'thir, 'tcx>,
},
Loop {
body: &'thir Expr<'thir, 'tcx>,
},
Match {
scrutinee: &'thir Expr<'thir, 'tcx>,
arms: &'thir [Arm<'thir, 'tcx>],
},
Block {
body: Block<'thir, 'tcx>,
},
Assign {
lhs: &'thir Expr<'thir, 'tcx>,
rhs: &'thir Expr<'thir, 'tcx>,
},
AssignOp {
op: BinOp,
lhs: &'thir Expr<'thir, 'tcx>,
rhs: &'thir Expr<'thir, 'tcx>,
},
Field {
lhs: &'thir Expr<'thir, 'tcx>,
name: Field,
},
Index {
lhs: &'thir Expr<'thir, 'tcx>,
index: &'thir Expr<'thir, 'tcx>,
},
VarRef {
id: hir::HirId,
},
UpvarRef {
closure_def_id: DefId,
var_hir_id: hir::HirId,
},
Borrow {
borrow_kind: BorrowKind,
arg: &'thir Expr<'thir, 'tcx>,
},
AddressOf {
mutability: hir::Mutability,
arg: &'thir Expr<'thir, 'tcx>,
},
Break {
label: region::Scope,
value: Option<&'thir Expr<'thir, 'tcx>>,
},
Continue {
label: region::Scope,
},
Return {
value: Option<&'thir Expr<'thir, 'tcx>>,
},
ConstBlock {
value: &'tcx Const<'tcx>,
},
Repeat {
value: &'thir Expr<'thir, 'tcx>,
count: &'tcx Const<'tcx>,
},
Array {
fields: &'thir [Expr<'thir, 'tcx>],
},
Tuple {
fields: &'thir [Expr<'thir, 'tcx>],
},
Adt {
adt_def: &'tcx AdtDef,
variant_index: VariantIdx,
substs: SubstsRef<'tcx>,
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
fields: &'thir [FieldExpr<'thir, 'tcx>],
base: Option<FruInfo<'thir, 'tcx>>,
},
PlaceTypeAscription {
source: &'thir Expr<'thir, 'tcx>,
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
},
ValueTypeAscription {
source: &'thir Expr<'thir, 'tcx>,
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
},
Closure {
closure_id: DefId,
substs: UpvarSubsts<'tcx>,
upvars: &'thir [Expr<'thir, 'tcx>],
movability: Option<hir::Movability>,
fake_reads: Vec<(&'thir Expr<'thir, 'tcx>, FakeReadCause, hir::HirId)>,
},
Literal {
literal: &'tcx Const<'tcx>,
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
const_id: Option<DefId>,
},
StaticRef {
literal: &'tcx Const<'tcx>,
def_id: DefId,
},
InlineAsm {
template: &'tcx [InlineAsmTemplatePiece],
operands: &'thir [InlineAsmOperand<'thir, 'tcx>],
options: InlineAsmOptions,
line_spans: &'tcx [Span],
},
ThreadLocalRef(DefId),
LlvmInlineAsm {
asm: &'tcx hir::LlvmInlineAsmInner,
outputs: &'thir [Expr<'thir, 'tcx>],
inputs: &'thir [Expr<'thir, 'tcx>],
},
Yield {
value: &'thir Expr<'thir, 'tcx>,
},
}
#[derive(Debug)]
pub struct FieldExpr<'thir, 'tcx> {
pub name: Field,
pub expr: &'thir Expr<'thir, 'tcx>,
}
#[derive(Debug)]
pub struct FruInfo<'thir, 'tcx> {
pub base: &'thir Expr<'thir, 'tcx>,
pub field_types: &'thir [Ty<'tcx>],
}
#[derive(Debug)]
pub struct Arm<'thir, 'tcx> {
pub pattern: Pat<'tcx>,
pub guard: Option<Guard<'thir, 'tcx>>,
pub body: &'thir Expr<'thir, 'tcx>,
pub lint_level: LintLevel,
pub scope: region::Scope,
pub span: Span,
}
#[derive(Debug)]
pub enum Guard<'thir, 'tcx> {
If(&'thir Expr<'thir, 'tcx>),
IfLet(Pat<'tcx>, &'thir Expr<'thir, 'tcx>),
}
#[derive(Copy, Clone, Debug)]
pub enum LogicalOp {
And,
Or,
}
#[derive(Debug)]
pub enum InlineAsmOperand<'thir, 'tcx> {
In {
reg: InlineAsmRegOrRegClass,
expr: &'thir Expr<'thir, 'tcx>,
},
Out {
reg: InlineAsmRegOrRegClass,
late: bool,
expr: Option<&'thir Expr<'thir, 'tcx>>,
},
InOut {
reg: InlineAsmRegOrRegClass,
late: bool,
expr: &'thir Expr<'thir, 'tcx>,
},
SplitInOut {
reg: InlineAsmRegOrRegClass,
late: bool,
in_expr: &'thir Expr<'thir, 'tcx>,
out_expr: Option<&'thir Expr<'thir, 'tcx>>,
},
Const {
expr: &'thir Expr<'thir, 'tcx>,
},
SymFn {
expr: &'thir Expr<'thir, 'tcx>,
},
SymStatic {
def_id: DefId,
},
}