]> git.proxmox.com Git - rustc.git/blame - src/librustc_mir/hair/cx/to_ref.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc_mir / hair / cx / to_ref.rs
CommitLineData
e9174d1e
SL
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.
4//
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.
10
11use hair::*;
e9174d1e 12
54a0048b 13use rustc::hir;
b039eaaf 14use syntax::ptr::P;
e9174d1e 15
b039eaaf 16pub trait ToRef {
e9174d1e
SL
17 type Output;
18 fn to_ref(self) -> Self::Output;
19}
20
b039eaaf
SL
21impl<'a,'tcx:'a> ToRef for &'tcx hir::Expr {
22 type Output = ExprRef<'tcx>;
e9174d1e 23
b039eaaf 24 fn to_ref(self) -> ExprRef<'tcx> {
e9174d1e
SL
25 ExprRef::Hair(self)
26 }
27}
28
b039eaaf
SL
29impl<'a,'tcx:'a> ToRef for &'tcx P<hir::Expr> {
30 type Output = ExprRef<'tcx>;
e9174d1e 31
b039eaaf 32 fn to_ref(self) -> ExprRef<'tcx> {
e9174d1e
SL
33 ExprRef::Hair(&**self)
34 }
35}
36
b039eaaf
SL
37impl<'a,'tcx:'a> ToRef for Expr<'tcx> {
38 type Output = ExprRef<'tcx>;
e9174d1e 39
b039eaaf 40 fn to_ref(self) -> ExprRef<'tcx> {
e9174d1e
SL
41 ExprRef::Mirror(Box::new(self))
42 }
43}
44
b039eaaf
SL
45impl<'a,'tcx:'a,T,U> ToRef for &'tcx Option<T>
46 where &'tcx T: ToRef<Output=U>
e9174d1e
SL
47{
48 type Output = Option<U>;
49
50 fn to_ref(self) -> Option<U> {
51 self.as_ref().map(|expr| expr.to_ref())
52 }
53}
54
b039eaaf
SL
55impl<'a,'tcx:'a,T,U> ToRef for &'tcx Vec<T>
56 where &'tcx T: ToRef<Output=U>
e9174d1e
SL
57{
58 type Output = Vec<U>;
59
60 fn to_ref(self) -> Vec<U> {
61 self.iter().map(|expr| expr.to_ref()).collect()
62 }
63}
9cc50fc6
SL
64
65impl<'a,'tcx:'a,T,U> ToRef for &'tcx P<[T]>
66 where &'tcx T: ToRef<Output=U>
67{
68 type Output = Vec<U>;
69
70 fn to_ref(self) -> Vec<U> {
71 self.iter().map(|expr| expr.to_ref()).collect()
72 }
73}