]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir_build/build/into.rs
compiletest: Do not run debuginfo tests with gdb on msvc targets
[rust.git] / src / librustc_mir_build / 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     crate fn into<E>(
22         &mut self,
23         destination: &Place<'tcx>,
24         block: BasicBlock,
25         expr: E,
26     ) -> BlockAnd<()>
27     where
28         E: EvalInto<'tcx>,
29     {
30         expr.eval_into(self, destination, block)
31     }
32 }
33
34 impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
35     fn eval_into(
36         self,
37         builder: &mut Builder<'_, 'tcx>,
38         destination: &Place<'tcx>,
39         block: BasicBlock,
40     ) -> BlockAnd<()> {
41         let expr = builder.hir.mirror(self);
42         builder.into_expr(destination, block, expr)
43     }
44 }
45
46 impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
47     fn eval_into(
48         self,
49         builder: &mut Builder<'_, 'tcx>,
50         destination: &Place<'tcx>,
51         block: BasicBlock,
52     ) -> BlockAnd<()> {
53         builder.into_expr(destination, block, self)
54     }
55 }