]> git.proxmox.com Git - rustc.git/blame - src/librustc_mir_build/build/into.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_mir_build / build / into.rs
CommitLineData
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 7use crate::build::{BlockAnd, Builder};
3dfed10e 8use crate::thir::*;
ba9703b0 9use rustc_middle::mir::*;
e9174d1e 10
9fa01778 11pub(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 20impl<'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 34impl<'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 46impl<'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}