diff options
| author | Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com> | 2016-06-06 20:22:48 +0530 |
|---|---|---|
| committer | Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com> | 2016-08-12 09:40:12 +0530 |
| commit | d6526395244f533fd8cfd3bc1a86e2b5da963860 (patch) | |
| tree | 39fdbb0670259fb3ec658653da99dc071c7c9f16 /src/libsyntax_ext/deriving/generic | |
| parent | 8787a12334439d47e931be26fef53381ce337c3a (diff) | |
| download | rust-d6526395244f533fd8cfd3bc1a86e2b5da963860.tar.gz rust-d6526395244f533fd8cfd3bc1a86e2b5da963860.zip | |
run rustfmt on libsyntax_ext folder
Diffstat (limited to 'src/libsyntax_ext/deriving/generic')
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/ty.rs | 133 |
1 files changed, 70 insertions, 63 deletions
diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 626fbaada5c..356c54fcf31 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -36,20 +36,20 @@ pub enum PtrTy<'a> { /// for type parameters and a lifetime. #[derive(Clone, Eq, PartialEq)] pub struct Path<'a> { - pub path: Vec<&'a str> , + pub path: Vec<&'a str>, pub lifetime: Option<&'a str>, pub params: Vec<Box<Ty<'a>>>, pub global: bool, } impl<'a> Path<'a> { - pub fn new<'r>(path: Vec<&'r str> ) -> Path<'r> { + pub fn new<'r>(path: Vec<&'r str>) -> Path<'r> { Path::new_(path, None, Vec::new(), true) } pub fn new_local<'r>(path: &'r str) -> Path<'r> { - Path::new_(vec!( path ), None, Vec::new(), false) + Path::new_(vec![path], None, Vec::new(), false) } - pub fn new_<'r>(path: Vec<&'r str> , + pub fn new_<'r>(path: Vec<&'r str>, lifetime: Option<&'r str>, params: Vec<Box<Ty<'r>>>, global: bool) @@ -58,7 +58,7 @@ impl<'a> Path<'a> { path: path, lifetime: lifetime, params: params, - global: global + global: global, } } @@ -94,7 +94,7 @@ pub enum Ty<'a> { /// parameter, and things like `i32` Literal(Path<'a>), /// includes unit - Tuple(Vec<Ty<'a>> ) + Tuple(Vec<Ty<'a>>), } pub fn borrowed_ptrty<'r>() -> PtrTy<'r> { @@ -119,14 +119,14 @@ pub fn nil_ty<'r>() -> Ty<'r> { fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> { match *lt { Some(ref s) => Some(cx.lifetime(span, cx.ident_of(*s).name)), - None => None + None => None, } } fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> { match *lt { - Some(ref s) => vec!(cx.lifetime(span, cx.ident_of(*s).name)), - None => vec!() + Some(ref s) => vec![cx.lifetime(span, cx.ident_of(*s).name)], + None => vec![], } } @@ -145,13 +145,11 @@ impl<'a> Ty<'a> { let lt = mk_lifetime(cx, span, lt); cx.ty_rptr(span, raw_ty, lt, mutbl) } - Raw(mutbl) => cx.ty_ptr(span, raw_ty, mutbl) + Raw(mutbl) => cx.ty_ptr(span, raw_ty, mutbl), } } - Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) } - Self_ => { - cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) - } + Literal(ref p) => p.to_ty(cx, span, self_ty, self_generics), + Self_ => cx.ty_path(self.to_path(cx, span, self_ty, self_generics)), Tuple(ref fields) => { let ty = ast::TyKind::Tup(fields.iter() .map(|f| f.to_ty(cx, span, self_ty, self_generics)) @@ -169,20 +167,25 @@ impl<'a> Ty<'a> { -> ast::Path { match *self { Self_ => { - let self_params = self_generics.ty_params.iter().map(|ty_param| { - cx.ty_ident(span, ty_param.ident) - }).collect(); - let lifetimes = self_generics.lifetimes.iter() - .map(|d| d.lifetime) - .collect(); + let self_params = self_generics.ty_params + .iter() + .map(|ty_param| cx.ty_ident(span, ty_param.ident)) + .collect(); + let lifetimes = self_generics.lifetimes + .iter() + .map(|d| d.lifetime) + .collect(); - cx.path_all(span, false, vec![self_ty], lifetimes, self_params, Vec::new()) - } - Literal(ref p) => { - p.to_path(cx, span, self_ty, self_generics) + cx.path_all(span, + false, + vec![self_ty], + lifetimes, + self_params, + Vec::new()) } - Ptr(..) => { cx.span_bug(span, "pointer in a path in generic `derive`") } - Tuple(..) => { cx.span_bug(span, "tuple in a path in generic `derive`") } + Literal(ref p) => p.to_path(cx, span, self_ty, self_generics), + Ptr(..) => cx.span_bug(span, "pointer in a path in generic `derive`"), + Tuple(..) => cx.span_bug(span, "tuple in a path in generic `derive`"), } } } @@ -195,16 +198,16 @@ fn mk_ty_param(cx: &ExtCtxt, self_ident: Ident, self_generics: &Generics) -> ast::TyParam { - let bounds = - bounds.iter().map(|b| { + let bounds = bounds.iter() + .map(|b| { let path = b.to_path(cx, span, self_ident, self_generics); cx.typarambound(path) - }).collect(); + }) + .collect(); cx.typaram(span, cx.ident_of(name), bounds, None) } -fn mk_generics(lifetimes: Vec<ast::LifetimeDef>, ty_params: Vec<ast::TyParam>) - -> Generics { +fn mk_generics(lifetimes: Vec<ast::LifetimeDef>, ty_params: Vec<ast::TyParam>) -> Generics { Generics { lifetimes: lifetimes, ty_params: P::from_vec(ty_params), @@ -225,7 +228,8 @@ pub struct LifetimeBounds<'a> { impl<'a> LifetimeBounds<'a> { pub fn empty() -> LifetimeBounds<'a> { LifetimeBounds { - lifetimes: Vec::new(), bounds: Vec::new() + lifetimes: Vec::new(), + bounds: Vec::new(), } } pub fn to_generics(&self, @@ -234,46 +238,49 @@ impl<'a> LifetimeBounds<'a> { self_ty: Ident, self_generics: &Generics) -> Generics { - let lifetimes = self.lifetimes.iter().map(|&(ref lt, ref bounds)| { - let bounds = - bounds.iter().map( - |b| cx.lifetime(span, cx.ident_of(*b).name)).collect(); - cx.lifetime_def(span, cx.ident_of(*lt).name, bounds) - }).collect(); - let ty_params = self.bounds.iter().map(|t| { - match *t { - (ref name, ref bounds) => { - mk_ty_param(cx, - span, - *name, - bounds, - self_ty, - self_generics) + let lifetimes = self.lifetimes + .iter() + .map(|&(ref lt, ref bounds)| { + let bounds = bounds.iter() + .map(|b| cx.lifetime(span, cx.ident_of(*b).name)) + .collect(); + cx.lifetime_def(span, cx.ident_of(*lt).name, bounds) + }) + .collect(); + let ty_params = self.bounds + .iter() + .map(|t| { + match *t { + (ref name, ref bounds) => { + mk_ty_param(cx, span, *name, bounds, self_ty, self_generics) + } } - } - }).collect(); + }) + .collect(); mk_generics(lifetimes, ty_params) } } -pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>) - -> (P<Expr>, ast::ExplicitSelf) { +pub fn get_explicit_self(cx: &ExtCtxt, + span: Span, + self_ptr: &Option<PtrTy>) + -> (P<Expr>, ast::ExplicitSelf) { // this constructs a fresh `self` path let self_path = cx.expr_self(span); match *self_ptr { - None => { - (self_path, respan(span, SelfKind::Value(ast::Mutability::Immutable))) - } + None => (self_path, respan(span, SelfKind::Value(ast::Mutability::Immutable))), Some(ref ptr) => { - let self_ty = respan( - span, - match *ptr { - Borrowed(ref lt, mutbl) => { - let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name)); - SelfKind::Region(lt, mutbl) - } - Raw(_) => cx.span_bug(span, "attempted to use *self in deriving definition") - }); + let self_ty = + respan(span, + match *ptr { + Borrowed(ref lt, mutbl) => { + let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name)); + SelfKind::Region(lt, mutbl) + } + Raw(_) => { + cx.span_bug(span, "attempted to use *self in deriving definition") + } + }); let self_expr = cx.expr_deref(span, self_path); (self_expr, self_ty) } |
