]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_mir_build/src/thir/cx/to_ref.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_mir_build / src / thir / cx / to_ref.rs
1 use crate::thir::*;
2
3 use rustc_hir as hir;
4
5 crate trait ToRef {
6 type Output;
7 fn to_ref(self) -> Self::Output;
8 }
9
10 impl<'tcx> ToRef for &'tcx hir::Expr<'tcx> {
11 type Output = ExprRef<'tcx>;
12
13 fn to_ref(self) -> ExprRef<'tcx> {
14 ExprRef::Thir(self)
15 }
16 }
17
18 impl<'tcx> ToRef for &'tcx &'tcx hir::Expr<'tcx> {
19 type Output = ExprRef<'tcx>;
20
21 fn to_ref(self) -> ExprRef<'tcx> {
22 ExprRef::Thir(&**self)
23 }
24 }
25
26 impl<'tcx> ToRef for Expr<'tcx> {
27 type Output = ExprRef<'tcx>;
28
29 fn to_ref(self) -> ExprRef<'tcx> {
30 ExprRef::Mirror(Box::new(self))
31 }
32 }
33
34 impl<'tcx, T, U> ToRef for &'tcx Option<T>
35 where
36 &'tcx T: ToRef<Output = U>,
37 {
38 type Output = Option<U>;
39
40 fn to_ref(self) -> Option<U> {
41 self.as_ref().map(|expr| expr.to_ref())
42 }
43 }
44
45 impl<'tcx, T, U> ToRef for &'tcx Vec<T>
46 where
47 &'tcx T: ToRef<Output = U>,
48 {
49 type Output = Vec<U>;
50
51 fn to_ref(self) -> Vec<U> {
52 self.iter().map(|expr| expr.to_ref()).collect()
53 }
54 }
55
56 impl<'tcx, T, U> ToRef for &'tcx [T]
57 where
58 &'tcx T: ToRef<Output = U>,
59 {
60 type Output = Vec<U>;
61
62 fn to_ref(self) -> Vec<U> {
63 self.iter().map(|expr| expr.to_ref()).collect()
64 }
65 }