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.
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.
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.
17 use build::{BlockAnd, Builder};
21 pub trait EvalInto<'tcx> {
22 fn eval_into<'a, 'gcx>(self,
23 builder: &mut Builder<'a, 'gcx, 'tcx>,
24 destination: &Lvalue<'tcx>,
29 impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
30 pub fn into<E>(&mut self,
31 destination: &Lvalue<'tcx>,
35 where E: EvalInto<'tcx>
37 expr.eval_into(self, destination, block)
41 impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
42 fn eval_into<'a, 'gcx>(self,
43 builder: &mut Builder<'a, 'gcx, 'tcx>,
44 destination: &Lvalue<'tcx>,
47 let expr = builder.hir.mirror(self);
48 builder.into_expr(destination, block, expr)
52 impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
53 fn eval_into<'a, 'gcx>(self,
54 builder: &mut Builder<'a, 'gcx, 'tcx>,
55 destination: &Lvalue<'tcx>,
58 builder.into_expr(destination, block, self)