]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/build/into.rs
Allow a dirty MirBuilt for make_extern and make_method_extern
[rust.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 build::{BlockAnd, Builder};
8 use hair::*;
9 use rustc::mir::*;
10
11 pub(in build) trait EvalInto<'tcx> {
12     fn eval_into<'a, 'gcx>(self,
13                            builder: &mut Builder<'a, 'gcx, 'tcx>,
14                            destination: &Place<'tcx>,
15                            block: BasicBlock)
16                            -> BlockAnd<()>;
17 }
18
19 impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
20     pub fn into<E>(&mut self,
21                    destination: &Place<'tcx>,
22                    block: BasicBlock,
23                    expr: E)
24                    -> BlockAnd<()>
25         where E: EvalInto<'tcx>
26     {
27         expr.eval_into(self, destination, block)
28     }
29 }
30
31 impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
32     fn eval_into<'a, 'gcx>(self,
33                            builder: &mut Builder<'a, 'gcx, 'tcx>,
34                            destination: &Place<'tcx>,
35                            block: BasicBlock)
36                            -> BlockAnd<()> {
37         let expr = builder.hir.mirror(self);
38         builder.into_expr(destination, block, expr)
39     }
40 }
41
42 impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
43     fn eval_into<'a, 'gcx>(self,
44                            builder: &mut Builder<'a, 'gcx, 'tcx>,
45                            destination: &Place<'tcx>,
46                            block: BasicBlock)
47                            -> BlockAnd<()> {
48         builder.into_expr(destination, block, self)
49     }
50 }