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
|
2018-11-27 02:59:49 +00:00
|
|
|
//! 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> {
|
2019-06-01 11:38:36 +00:00
|
|
|
fn eval_into(
|
|
|
|
self,
|
|
|
|
builder: &mut Builder<'_, 'tcx>,
|
2020-03-31 17:08:48 +00:00
|
|
|
destination: Place<'tcx>,
|
2019-06-01 11:38:36 +00:00
|
|
|
block: BasicBlock,
|
|
|
|
) -> BlockAnd<()>;
|
2015-08-18 21:59:21 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 11:38:36 +00:00
|
|
|
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
2020-01-05 15:46:44 +00:00
|
|
|
crate fn into<E>(
|
|
|
|
&mut self,
|
2020-03-31 17:08:48 +00:00
|
|
|
destination: Place<'tcx>,
|
2020-01-05 15:46:44 +00:00
|
|
|
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
|
|
|
{
|
2019-10-09 19:06:15 +00:00
|
|
|
expr.eval_into(self, destination, block)
|
2015-08-18 21:59:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 16:31:48 +00:00
|
|
|
impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
|
2019-06-01 11:38:36 +00:00
|
|
|
fn eval_into(
|
|
|
|
self,
|
|
|
|
builder: &mut Builder<'_, 'tcx>,
|
2020-03-31 17:08:48 +00:00
|
|
|
destination: Place<'tcx>,
|
2019-06-01 11:38:36 +00:00
|
|
|
block: BasicBlock,
|
|
|
|
) -> BlockAnd<()> {
|
2015-08-18 21:59:21 +00:00
|
|
|
let expr = builder.hir.mirror(self);
|
2019-10-09 19:06:15 +00:00
|
|
|
builder.into_expr(destination, block, expr)
|
2015-08-18 21:59:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 16:31:48 +00:00
|
|
|
impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
|
2019-06-01 11:38:36 +00:00
|
|
|
fn eval_into(
|
|
|
|
self,
|
|
|
|
builder: &mut Builder<'_, 'tcx>,
|
2020-03-31 17:08:48 +00:00
|
|
|
destination: Place<'tcx>,
|
2019-06-01 11:38:36 +00:00
|
|
|
block: BasicBlock,
|
|
|
|
) -> BlockAnd<()> {
|
2019-10-09 19:06:15 +00:00
|
|
|
builder.into_expr(destination, block, self)
|
2015-08-18 21:59:21 +00:00
|
|
|
}
|
|
|
|
}
|