]>
Commit | Line | Data |
---|---|---|
e9174d1e SL |
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 | |
0731742a | 4 | //! wrapped up as expressions (e.g., blocks). To make this ergonomic, we use this |
e9174d1e SL |
5 | //! latter `EvalInto` trait. |
6 | ||
9fa01778 | 7 | use crate::build::{BlockAnd, Builder}; |
3dfed10e | 8 | use crate::thir::*; |
ba9703b0 | 9 | use rustc_middle::mir::*; |
e9174d1e | 10 | |
9fa01778 | 11 | pub(in crate::build) trait EvalInto<'tcx> { |
dc9dc135 XL |
12 | fn eval_into( |
13 | self, | |
14 | builder: &mut Builder<'_, 'tcx>, | |
ba9703b0 | 15 | destination: Place<'tcx>, |
dc9dc135 XL |
16 | block: BasicBlock, |
17 | ) -> BlockAnd<()>; | |
e9174d1e SL |
18 | } |
19 | ||
dc9dc135 | 20 | impl<'a, 'tcx> Builder<'a, 'tcx> { |
dfeec247 XL |
21 | crate fn into<E>( |
22 | &mut self, | |
ba9703b0 | 23 | destination: Place<'tcx>, |
dfeec247 XL |
24 | block: BasicBlock, |
25 | expr: E, | |
26 | ) -> BlockAnd<()> | |
27 | where | |
28 | E: EvalInto<'tcx>, | |
e9174d1e SL |
29 | { |
30 | expr.eval_into(self, destination, block) | |
31 | } | |
32 | } | |
33 | ||
b039eaaf | 34 | impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> { |
dc9dc135 XL |
35 | fn eval_into( |
36 | self, | |
37 | builder: &mut Builder<'_, 'tcx>, | |
ba9703b0 | 38 | destination: Place<'tcx>, |
dc9dc135 XL |
39 | block: BasicBlock, |
40 | ) -> BlockAnd<()> { | |
e9174d1e SL |
41 | let expr = builder.hir.mirror(self); |
42 | builder.into_expr(destination, block, expr) | |
43 | } | |
44 | } | |
45 | ||
b039eaaf | 46 | impl<'tcx> EvalInto<'tcx> for Expr<'tcx> { |
dc9dc135 XL |
47 | fn eval_into( |
48 | self, | |
49 | builder: &mut Builder<'_, 'tcx>, | |
ba9703b0 | 50 | destination: Place<'tcx>, |
dc9dc135 XL |
51 | block: BasicBlock, |
52 | ) -> BlockAnd<()> { | |
e9174d1e SL |
53 | builder.into_expr(destination, block, self) |
54 | } | |
55 | } |