rust/compiler/rustc_mir_build/src/build/into.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

2015-08-18 21:59:21 +00:00
//! In general, there are a number of things for which it's convenient
//! to just call `builder.into` and have it emit its result into a
//! given location. This is basically for expressions or things that can be
//! wrapped up as expressions (e.g., blocks). To make this ergonomic, we use this
2015-08-18 21:59:21 +00:00
//! latter `EvalInto` trait.
2019-02-07 21:28:15 +00:00
use crate::build::{BlockAnd, Builder};
2020-07-21 09:09:27 +00:00
use crate::thir::*;
2020-03-29 14:41:09 +00:00
use rustc_middle::mir::*;
2015-08-18 21:59:21 +00:00
2019-02-07 21:28:15 +00:00
pub(in crate::build) trait EvalInto<'tcx> {
fn eval_into(
self,
builder: &mut Builder<'_, 'tcx>,
destination: Place<'tcx>,
block: BasicBlock,
) -> BlockAnd<()>;
2015-08-18 21:59:21 +00:00
}
impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn into<E>(
&mut self,
destination: Place<'tcx>,
block: BasicBlock,
expr: E,
) -> BlockAnd<()>
2019-12-22 22:42:04 +00:00
where
E: EvalInto<'tcx>,
2015-08-18 21:59:21 +00:00
{
expr.eval_into(self, destination, block)
2015-08-18 21:59:21 +00:00
}
}
impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
fn eval_into(
self,
builder: &mut Builder<'_, 'tcx>,
destination: Place<'tcx>,
block: BasicBlock,
) -> BlockAnd<()> {
2015-08-18 21:59:21 +00:00
let expr = builder.hir.mirror(self);
builder.into_expr(destination, block, expr)
2015-08-18 21:59:21 +00:00
}
}
impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
fn eval_into(
self,
builder: &mut Builder<'_, 'tcx>,
destination: Place<'tcx>,
block: BasicBlock,
) -> BlockAnd<()> {
builder.into_expr(destination, block, self)
2015-08-18 21:59:21 +00:00
}
}