]> git.proxmox.com Git - rustc.git/blob - src/librustc_mir/build/into.rs
Imported Upstream version 1.7.0+dfsg1
[rustc.git] / src / librustc_mir / build / into.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! In general, there are a number of things for which it's convenient
12 //! to just call `builder.into` and have it emit its result into a
13 //! given location. This is basically for expressions or things that can be
14 //! wrapped up as expressions (e.g. blocks). To make this ergonomic, we use this
15 //! latter `EvalInto` trait.
16
17 use build::{BlockAnd, Builder};
18 use hair::*;
19 use rustc::mir::repr::*;
20
21 pub trait EvalInto<'tcx> {
22 fn eval_into<'a>(self,
23 builder: &mut Builder<'a, 'tcx>,
24 destination: &Lvalue<'tcx>,
25 block: BasicBlock)
26 -> BlockAnd<()>;
27 }
28
29 impl<'a,'tcx> Builder<'a,'tcx> {
30 pub fn into<E>(&mut self,
31 destination: &Lvalue<'tcx>,
32 block: BasicBlock,
33 expr: E)
34 -> BlockAnd<()>
35 where E: EvalInto<'tcx>
36 {
37 expr.eval_into(self, destination, block)
38 }
39 }
40
41 impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
42 fn eval_into<'a>(self,
43 builder: &mut Builder<'a, 'tcx>,
44 destination: &Lvalue<'tcx>,
45 block: BasicBlock)
46 -> BlockAnd<()> {
47 let expr = builder.hir.mirror(self);
48 builder.into_expr(destination, block, expr)
49 }
50 }
51
52 impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
53 fn eval_into<'a>(self,
54 builder: &mut Builder<'a, 'tcx>,
55 destination: &Lvalue<'tcx>,
56 block: BasicBlock)
57 -> BlockAnd<()> {
58 builder.into_expr(destination, block, self)
59 }
60 }