]> git.proxmox.com Git - rustc.git/blob - src/librustc_mir/build/into.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / librustc_mir / build / into.rs
1 //! In general, there are a number of things for which it's convenient
2 //! to just call `builder.into` and have it emit its result into a
3 //! given location. This is basically for expressions or things that can be
4 //! wrapped up as expressions (e.g., blocks). To make this ergonomic, we use this
5 //! latter `EvalInto` trait.
6
7 use crate::build::{BlockAnd, Builder};
8 use crate::hair::*;
9 use rustc::mir::*;
10
11 pub(in crate::build) trait EvalInto<'tcx> {
12 fn eval_into(
13 self,
14 builder: &mut Builder<'_, 'tcx>,
15 destination: &Place<'tcx>,
16 block: BasicBlock,
17 ) -> BlockAnd<()>;
18 }
19
20 impl<'a, 'tcx> Builder<'a, 'tcx> {
21 pub fn into<E>(&mut self,
22 destination: &Place<'tcx>,
23 block: BasicBlock,
24 expr: E)
25 -> BlockAnd<()>
26 where E: EvalInto<'tcx>
27 {
28 expr.eval_into(self, destination, block)
29 }
30 }
31
32 impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
33 fn eval_into(
34 self,
35 builder: &mut Builder<'_, 'tcx>,
36 destination: &Place<'tcx>,
37 block: BasicBlock,
38 ) -> BlockAnd<()> {
39 let expr = builder.hir.mirror(self);
40 builder.into_expr(destination, block, expr)
41 }
42 }
43
44 impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
45 fn eval_into(
46 self,
47 builder: &mut Builder<'_, 'tcx>,
48 destination: &Place<'tcx>,
49 block: BasicBlock,
50 ) -> BlockAnd<()> {
51 builder.into_expr(destination, block, self)
52 }
53 }