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.
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.
11 // Lowers the AST to the HIR
17 use syntax::codemap::Spanned;
18 use syntax::owned_slice::OwnedSlice;
21 pub fn lower_view_path(view_path: &ViewPath) -> P<hir::ViewPath> {
23 node: match view_path.node {
24 ViewPathSimple(ident, ref path) => {
25 hir::ViewPathSimple(ident, lower_path(path))
27 ViewPathGlob(ref path) => {
28 hir::ViewPathGlob(lower_path(path))
30 ViewPathList(ref path, ref path_list_idents) => {
31 hir::ViewPathList(lower_path(path),
32 path_list_idents.iter().map(|path_list_ident| {
34 node: match path_list_ident.node {
35 PathListIdent { id, name, rename } =>
39 rename: rename.clone(),
41 PathListMod { id, rename } =>
42 hir::PathListMod { id: id, rename: rename.clone() }
44 span: path_list_ident.span
53 pub fn lower_arm(arm: &Arm) -> hir::Arm {
55 attrs: arm.attrs.clone(),
56 pats: arm.pats.iter().map(|x| lower_pat(x)).collect(),
57 guard: arm.guard.as_ref().map(|ref x| lower_expr(x)),
58 body: lower_expr(&arm.body),
62 pub fn lower_decl(d: &Decl) -> P<hir::Decl> {
64 DeclLocal(ref l) => P(Spanned {
65 node: hir::DeclLocal(lower_local(l)),
68 DeclItem(ref it) => P(Spanned {
69 node: hir::DeclItem(lower_item(it)),
75 pub fn lower_ty_binding(b: &TypeBinding) -> P<hir::TypeBinding> {
76 P(hir::TypeBinding { id: b.id, ident: b.ident, ty: lower_ty(&b.ty), span: b.span })
79 pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
83 TyInfer => hir::TyInfer,
84 TyVec(ref ty) => hir::TyVec(lower_ty(ty)),
85 TyPtr(ref mt) => hir::TyPtr(lower_mt(mt)),
86 TyRptr(ref region, ref mt) => {
87 hir::TyRptr(lower_opt_lifetime(region), lower_mt(mt))
90 hir::TyBareFn(P(hir::BareFnTy {
91 lifetimes: lower_lifetime_defs(&f.lifetimes),
92 unsafety: lower_unsafety(f.unsafety),
94 decl: lower_fn_decl(&f.decl)
97 TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(ty)).collect()),
98 TyParen(ref ty) => hir::TyParen(lower_ty(ty)),
99 TyPath(ref qself, ref path) => {
100 let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
106 hir::TyPath(qself, lower_path(path))
108 TyObjectSum(ref ty, ref bounds) => {
109 hir::TyObjectSum(lower_ty(ty),
110 lower_bounds(bounds))
112 TyFixedLengthVec(ref ty, ref e) => {
113 hir::TyFixedLengthVec(lower_ty(ty), lower_expr(e))
115 TyTypeof(ref expr) => {
116 hir::TyTypeof(lower_expr(expr))
118 TyPolyTraitRef(ref bounds) => {
119 hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(b)).collect())
121 TyMac(_) => panic!("TyMac should have been expanded by now."),
127 pub fn lower_foreign_mod(fm: &ForeignMod) -> hir::ForeignMod {
130 items: fm.items.iter().map(|x| lower_foreign_item(x)).collect(),
134 pub fn lower_variant(v: &Variant) -> P<hir::Variant> {
136 node: hir::Variant_ {
139 attrs: v.node.attrs.clone(),
140 kind: match v.node.kind {
141 TupleVariantKind(ref variant_args) => {
142 hir::TupleVariantKind(variant_args.iter().map(|ref x|
143 lower_variant_arg(x)).collect())
145 StructVariantKind(ref struct_def) => {
146 hir::StructVariantKind(lower_struct_def(struct_def))
149 disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(e)),
150 vis: lower_visibility(v.node.vis),
156 pub fn lower_path(p: &Path) -> hir::Path {
159 segments: p.segments.iter().map(|&PathSegment {identifier, ref parameters}|
161 identifier: identifier,
162 parameters: lower_path_parameters(parameters),
168 pub fn lower_path_parameters(path_parameters: &PathParameters) -> hir::PathParameters {
169 match *path_parameters {
170 AngleBracketedParameters(ref data) =>
171 hir::AngleBracketedParameters(lower_angle_bracketed_parameter_data(data)),
172 ParenthesizedParameters(ref data) =>
173 hir::ParenthesizedParameters(lower_parenthesized_parameter_data(data)),
177 pub fn lower_angle_bracketed_parameter_data(data: &AngleBracketedParameterData)
178 -> hir::AngleBracketedParameterData {
179 let &AngleBracketedParameterData { ref lifetimes, ref types, ref bindings } = data;
180 hir::AngleBracketedParameterData {
181 lifetimes: lower_lifetimes(lifetimes),
182 types: types.iter().map(|ty| lower_ty(ty)).collect(),
183 bindings: bindings.iter().map(|b| lower_ty_binding(b)).collect(),
187 pub fn lower_parenthesized_parameter_data(data: &ParenthesizedParameterData)
188 -> hir::ParenthesizedParameterData {
189 let &ParenthesizedParameterData { ref inputs, ref output, span } = data;
190 hir::ParenthesizedParameterData {
191 inputs: inputs.iter().map(|ty| lower_ty(ty)).collect(),
192 output: output.as_ref().map(|ty| lower_ty(ty)),
197 pub fn lower_local(l: &Local) -> P<hir::Local> {
200 ty: l.ty.as_ref().map(|t| lower_ty(t)),
201 pat: lower_pat(&l.pat),
202 init: l.init.as_ref().map(|e| lower_expr(e)),
207 pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ {
209 SelfStatic => hir::SelfStatic,
210 SelfValue(v) => hir::SelfValue(v),
211 SelfRegion(ref lifetime, m, ident) => {
212 hir::SelfRegion(lower_opt_lifetime(lifetime), lower_mutability(m), ident)
214 SelfExplicit(ref typ, ident) => {
215 hir::SelfExplicit(lower_ty(typ), ident)
220 pub fn lower_mutability(m: Mutability) -> hir::Mutability {
222 MutMutable => hir::MutMutable,
223 MutImmutable => hir::MutImmutable,
227 pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf {
228 Spanned { node: lower_explicit_self_underscore(&s.node), span: s.span }
231 pub fn lower_arg(arg: &Arg) -> hir::Arg {
232 hir::Arg { id: arg.id, pat: lower_pat(&arg.pat), ty: lower_ty(&arg.ty) }
235 pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
237 inputs: decl.inputs.iter().map(|x| lower_arg(x)).collect(),
238 output: match decl.output {
239 Return(ref ty) => hir::Return(lower_ty(ty)),
240 DefaultReturn(span) => hir::DefaultReturn(span),
241 NoReturn(span) => hir::NoReturn(span)
243 variadic: decl.variadic,
247 pub fn lower_ty_param_bound(tpb: &TyParamBound) -> hir::TyParamBound {
249 TraitTyParamBound(ref ty, modifier) => {
250 hir::TraitTyParamBound(lower_poly_trait_ref(ty), lower_trait_bound_modifier(modifier))
252 RegionTyParamBound(ref lifetime) => hir::RegionTyParamBound(lower_lifetime(lifetime)),
256 pub fn lower_ty_param(tp: &TyParam) -> hir::TyParam {
260 bounds: lower_bounds(&tp.bounds),
261 default: tp.default.as_ref().map(|x| lower_ty(x)),
266 pub fn lower_ty_params(tps: &OwnedSlice<TyParam>) -> OwnedSlice<hir::TyParam> {
267 tps.iter().map(|tp| lower_ty_param(tp)).collect()
270 pub fn lower_lifetime(l: &Lifetime) -> hir::Lifetime {
271 hir::Lifetime { id: l.id, name: l.name, span: l.span }
274 pub fn lower_lifetime_def(l: &LifetimeDef) -> hir::LifetimeDef {
275 hir::LifetimeDef { lifetime: lower_lifetime(&l.lifetime), bounds: lower_lifetimes(&l.bounds) }
278 pub fn lower_lifetimes(lts: &Vec<Lifetime>) -> Vec<hir::Lifetime> {
279 lts.iter().map(|l| lower_lifetime(l)).collect()
282 pub fn lower_lifetime_defs(lts: &Vec<LifetimeDef>) -> Vec<hir::LifetimeDef> {
283 lts.iter().map(|l| lower_lifetime_def(l)).collect()
286 pub fn lower_opt_lifetime(o_lt: &Option<Lifetime>) -> Option<hir::Lifetime> {
287 o_lt.as_ref().map(|lt| lower_lifetime(lt))
290 pub fn lower_generics(g: &Generics) -> hir::Generics {
292 ty_params: lower_ty_params(&g.ty_params),
293 lifetimes: lower_lifetime_defs(&g.lifetimes),
294 where_clause: lower_where_clause(&g.where_clause),
298 pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause {
301 predicates: wc.predicates.iter().map(|predicate|
302 lower_where_predicate(predicate)).collect(),
306 pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate {
308 WherePredicate::BoundPredicate(WhereBoundPredicate{ ref bound_lifetimes,
312 hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
313 bound_lifetimes: lower_lifetime_defs(bound_lifetimes),
314 bounded_ty: lower_ty(bounded_ty),
315 bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(),
319 WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
322 hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
324 lifetime: lower_lifetime(lifetime),
325 bounds: bounds.iter().map(|bound| lower_lifetime(bound)).collect()
328 WherePredicate::EqPredicate(WhereEqPredicate{ id,
332 hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{
334 path: lower_path(path),
342 pub fn lower_struct_def(sd: &StructDef) -> P<hir::StructDef> {
344 fields: sd.fields.iter().map(|f| lower_struct_field(f)).collect(),
349 pub fn lower_trait_ref(p: &TraitRef) -> hir::TraitRef {
350 hir::TraitRef { path: lower_path(&p.path), ref_id: p.ref_id }
353 pub fn lower_poly_trait_ref(p: &PolyTraitRef) -> hir::PolyTraitRef {
355 bound_lifetimes: lower_lifetime_defs(&p.bound_lifetimes),
356 trait_ref: lower_trait_ref(&p.trait_ref),
361 pub fn lower_struct_field(f: &StructField) -> hir::StructField {
363 node: hir::StructField_ {
365 kind: lower_struct_field_kind(&f.node.kind),
366 ty: lower_ty(&f.node.ty),
367 attrs: f.node.attrs.clone(),
373 pub fn lower_field(f: &Field) -> hir::Field {
374 hir::Field { ident: f.ident, expr: lower_expr(&f.expr), span: f.span }
377 pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
378 hir::MutTy { ty: lower_ty(&mt.ty), mutbl: lower_mutability(mt.mutbl) }
381 pub fn lower_opt_bounds(b: &Option<OwnedSlice<TyParamBound>>)
382 -> Option<OwnedSlice<hir::TyParamBound>> {
383 b.as_ref().map(|ref bounds| lower_bounds(bounds))
386 fn lower_bounds(bounds: &TyParamBounds) -> hir::TyParamBounds {
387 bounds.iter().map(|bound| lower_ty_param_bound(bound)).collect()
390 fn lower_variant_arg(va: &VariantArg) -> hir::VariantArg {
391 hir::VariantArg { id: va.id, ty: lower_ty(&va.ty) }
394 pub fn lower_block(b: &Block) -> P<hir::Block> {
397 stmts: b.stmts.iter().map(|s| lower_stmt(s)).collect(),
398 expr: b.expr.as_ref().map(|ref x| lower_expr(x)),
399 rules: lower_block_check_mode(&b.rules),
404 pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
406 ItemExternCrate(string) => hir::ItemExternCrate(string),
407 ItemUse(ref view_path) => {
408 hir::ItemUse(lower_view_path(view_path))
410 ItemStatic(ref t, m, ref e) => {
411 hir::ItemStatic(lower_ty(t), lower_mutability(m), lower_expr(e))
413 ItemConst(ref t, ref e) => {
414 hir::ItemConst(lower_ty(t), lower_expr(e))
416 ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
419 lower_unsafety(unsafety),
420 lower_constness(constness),
422 lower_generics(generics),
426 ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
427 ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)),
428 ItemTy(ref t, ref generics) => {
429 hir::ItemTy(lower_ty(t), lower_generics(generics))
431 ItemEnum(ref enum_definition, ref generics) => {
434 variants: enum_definition.variants.iter().map(|x| lower_variant(x)).collect(),
436 lower_generics(generics))
438 ItemStruct(ref struct_def, ref generics) => {
439 let struct_def = lower_struct_def(struct_def);
440 hir::ItemStruct(struct_def, lower_generics(generics))
442 ItemDefaultImpl(unsafety, ref trait_ref) => {
443 hir::ItemDefaultImpl(lower_unsafety(unsafety), lower_trait_ref(trait_ref))
445 ItemImpl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => {
446 let new_impl_items = impl_items.iter().map(|item| lower_impl_item(item)).collect();
447 let ifce = ifce.as_ref().map(|trait_ref| lower_trait_ref(trait_ref));
448 hir::ItemImpl(lower_unsafety(unsafety),
449 lower_impl_polarity(polarity),
450 lower_generics(generics),
455 ItemTrait(unsafety, ref generics, ref bounds, ref items) => {
456 let bounds = lower_bounds(bounds);
457 let items = items.iter().map(|item| lower_trait_item(item)).collect();
458 hir::ItemTrait(lower_unsafety(unsafety),
459 lower_generics(generics),
463 ItemMac(_) => panic!("Shouldn't still be around"),
467 pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
471 attrs: i.attrs.clone(),
473 ConstTraitItem(ref ty, ref default) => {
474 hir::ConstTraitItem(lower_ty(ty),
475 default.as_ref().map(|x| lower_expr(x)))
477 MethodTraitItem(ref sig, ref body) => {
478 hir::MethodTraitItem(lower_method_sig(sig),
479 body.as_ref().map(|x| lower_block(x)))
481 TypeTraitItem(ref bounds, ref default) => {
482 hir::TypeTraitItem(lower_bounds(bounds),
483 default.as_ref().map(|x| lower_ty(x)))
490 pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
494 attrs: i.attrs.clone(),
495 vis: lower_visibility(i.vis),
497 ConstImplItem(ref ty, ref expr) => {
498 hir::ConstImplItem(lower_ty(ty), lower_expr(expr))
500 MethodImplItem(ref sig, ref body) => {
501 hir::MethodImplItem(lower_method_sig(sig),
504 TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)),
505 MacImplItem(..) => panic!("Shouldn't exist any more"),
511 pub fn lower_mod(m: &Mod) -> hir::Mod {
512 hir::Mod { inner: m.inner, items: m.items.iter().map(|x| lower_item(x)).collect() }
515 pub fn lower_crate(c: &Crate) -> hir::Crate {
517 module: lower_mod(&c.module),
518 attrs: c.attrs.clone(),
519 config: c.config.clone(),
521 exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(m)).collect(),
525 pub fn lower_macro_def(m: &MacroDef) -> hir::MacroDef {
528 attrs: m.attrs.clone(),
531 imported_from: m.imported_from,
533 use_locally: m.use_locally,
534 allow_internal_unstable: m.allow_internal_unstable,
535 body: m.body.clone(),
539 // fold one item into possibly many items
540 pub fn lower_item(i: &Item) -> P<hir::Item> {
541 P(lower_item_simple(i))
544 // fold one item into exactly one item
545 pub fn lower_item_simple(i: &Item) -> hir::Item {
546 let node = lower_item_underscore(&i.node);
551 attrs: i.attrs.clone(),
553 vis: lower_visibility(i.vis),
558 pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
562 attrs: i.attrs.clone(),
564 ForeignItemFn(ref fdec, ref generics) => {
565 hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics))
567 ForeignItemStatic(ref t, m) => {
568 hir::ForeignItemStatic(lower_ty(t), m)
571 vis: lower_visibility(i.vis),
576 pub fn lower_method_sig(sig: &MethodSig) -> hir::MethodSig {
578 generics: lower_generics(&sig.generics),
580 explicit_self: lower_explicit_self(&sig.explicit_self),
581 unsafety: lower_unsafety(sig.unsafety),
582 constness: lower_constness(sig.constness),
583 decl: lower_fn_decl(&sig.decl),
587 pub fn lower_unsafety(u: Unsafety) -> hir::Unsafety {
589 Unsafety::Unsafe => hir::Unsafety::Unsafe,
590 Unsafety::Normal => hir::Unsafety::Normal,
594 pub fn lower_constness(c: Constness) -> hir::Constness {
596 Constness::Const => hir::Constness::Const,
597 Constness::NotConst => hir::Constness::NotConst,
601 pub fn lower_unop(u: UnOp) -> hir::UnOp {
603 UnUniq => hir::UnUniq,
604 UnDeref => hir::UnDeref,
610 pub fn lower_binop(b: BinOp) -> hir::BinOp {
620 BiBitXor => hir::BiBitXor,
621 BiBitAnd => hir::BiBitAnd,
622 BiBitOr => hir::BiBitOr,
636 pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
640 PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)),
641 PatIdent(ref binding_mode, pth1, ref sub) => {
642 hir::PatIdent(lower_binding_mode(binding_mode),
644 sub.as_ref().map(|x| lower_pat(x)))
646 PatLit(ref e) => hir::PatLit(lower_expr(e)),
647 PatEnum(ref pth, ref pats) => {
648 hir::PatEnum(lower_path(pth),
649 pats.as_ref().map(|pats| pats.iter().map(|x| lower_pat(x)).collect()))
651 PatQPath(ref qself, ref pth) => {
652 let qself = hir::QSelf {
653 ty: lower_ty(&qself.ty),
654 position: qself.position,
656 hir::PatQPath(qself, lower_path(pth))
658 PatStruct(ref pth, ref fields, etc) => {
659 let pth = lower_path(pth);
660 let fs = fields.iter().map(|f| {
661 Spanned { span: f.span,
662 node: hir::FieldPat {
664 pat: lower_pat(&f.node.pat),
665 is_shorthand: f.node.is_shorthand,
668 hir::PatStruct(pth, fs, etc)
670 PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()),
671 PatBox(ref inner) => hir::PatBox(lower_pat(inner)),
672 PatRegion(ref inner, mutbl) => hir::PatRegion(lower_pat(inner),
673 lower_mutability(mutbl)),
674 PatRange(ref e1, ref e2) => {
675 hir::PatRange(lower_expr(e1), lower_expr(e2))
677 PatVec(ref before, ref slice, ref after) => {
678 hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(),
679 slice.as_ref().map(|x| lower_pat(x)),
680 after.iter().map(|x| lower_pat(x)).collect())
682 PatMac(_) => panic!("Shouldn't exist here"),
688 pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
692 ExprBox(ref p, ref e) => {
693 hir::ExprBox(p.as_ref().map(|e| lower_expr(e)), lower_expr(e))
695 ExprVec(ref exprs) => {
696 hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
698 ExprRepeat(ref expr, ref count) => {
699 hir::ExprRepeat(lower_expr(expr), lower_expr(count))
701 ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
702 ExprCall(ref f, ref args) => {
703 hir::ExprCall(lower_expr(f),
704 args.iter().map(|x| lower_expr(x)).collect())
706 ExprMethodCall(i, ref tps, ref args) => {
709 tps.iter().map(|x| lower_ty(x)).collect(),
710 args.iter().map(|x| lower_expr(x)).collect())
712 ExprBinary(binop, ref lhs, ref rhs) => {
713 hir::ExprBinary(lower_binop(binop),
717 ExprUnary(op, ref ohs) => {
718 hir::ExprUnary(lower_unop(op), lower_expr(ohs))
720 ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
721 ExprCast(ref expr, ref ty) => {
722 hir::ExprCast(lower_expr(expr), lower_ty(ty))
724 ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
725 ExprIf(ref cond, ref tr, ref fl) => {
726 hir::ExprIf(lower_expr(cond),
728 fl.as_ref().map(|x| lower_expr(x)))
730 ExprWhile(ref cond, ref body, opt_ident) => {
731 hir::ExprWhile(lower_expr(cond),
735 ExprLoop(ref body, opt_ident) => {
736 hir::ExprLoop(lower_block(body),
739 ExprMatch(ref expr, ref arms, ref source) => {
740 hir::ExprMatch(lower_expr(expr),
741 arms.iter().map(|x| lower_arm(x)).collect(),
742 lower_match_source(source))
744 ExprClosure(capture_clause, ref decl, ref body) => {
745 hir::ExprClosure(lower_capture_clause(capture_clause),
749 ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
750 ExprAssign(ref el, ref er) => {
751 hir::ExprAssign(lower_expr(el), lower_expr(er))
753 ExprAssignOp(op, ref el, ref er) => {
754 hir::ExprAssignOp(lower_binop(op),
758 ExprField(ref el, ident) => {
759 hir::ExprField(lower_expr(el), ident)
761 ExprTupField(ref el, ident) => {
762 hir::ExprTupField(lower_expr(el), ident)
764 ExprIndex(ref el, ref er) => {
765 hir::ExprIndex(lower_expr(el), lower_expr(er))
767 ExprRange(ref e1, ref e2) => {
768 hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
769 e2.as_ref().map(|x| lower_expr(x)))
771 ExprPath(ref qself, ref path) => {
772 let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
778 hir::ExprPath(qself, lower_path(path))
780 ExprBreak(opt_ident) => hir::ExprBreak(opt_ident),
781 ExprAgain(opt_ident) => hir::ExprAgain(opt_ident),
782 ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(x))),
783 ExprInlineAsm(InlineAsm {
793 }) => hir::ExprInlineAsm(hir::InlineAsm {
794 inputs: inputs.iter().map(|&(ref c, ref input)| {
795 (c.clone(), lower_expr(input))
797 outputs: outputs.iter().map(|&(ref c, ref out, ref is_rw)| {
798 (c.clone(), lower_expr(out), *is_rw)
801 asm_str_style: asm_str_style,
802 clobbers: clobbers.clone(),
804 alignstack: alignstack,
805 dialect: lower_asm_dialect(dialect),
808 ExprStruct(ref path, ref fields, ref maybe_expr) => {
809 hir::ExprStruct(lower_path(path),
810 fields.iter().map(|x| lower_field(x)).collect(),
811 maybe_expr.as_ref().map(|x| lower_expr(x)))
813 ExprParen(ref ex) => hir::ExprParen(lower_expr(ex)),
817 ExprMac(_) => panic!("Shouldn't exist here"),
823 pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
825 StmtDecl(ref d, id) => {
827 node: hir::StmtDecl(lower_decl(d), id),
831 StmtExpr(ref e, id) => {
833 node: hir::StmtExpr(lower_expr(e), id),
837 StmtSemi(ref e, id) => {
839 node: hir::StmtSemi(lower_expr(e), id),
843 StmtMac(..) => panic!("Shouldn't exist here")
847 pub fn lower_match_source(m: &MatchSource) -> hir::MatchSource {
849 MatchSource::Normal => hir::MatchSource::Normal,
850 MatchSource::IfLetDesugar { contains_else_clause } => {
851 hir::MatchSource::IfLetDesugar { contains_else_clause: contains_else_clause }
853 MatchSource::WhileLetDesugar => hir::MatchSource::WhileLetDesugar,
854 MatchSource::ForLoopDesugar => hir::MatchSource::ForLoopDesugar,
858 pub fn lower_capture_clause(c: CaptureClause) -> hir::CaptureClause {
860 CaptureByValue => hir::CaptureByValue,
861 CaptureByRef => hir::CaptureByRef,
865 pub fn lower_asm_dialect(a: AsmDialect) -> hir::AsmDialect {
867 AsmAtt => hir::AsmAtt,
868 AsmIntel => hir::AsmIntel,
872 pub fn lower_visibility(v: Visibility) -> hir::Visibility {
874 Public => hir::Public,
875 Inherited => hir::Inherited,
879 pub fn lower_block_check_mode(b: &BlockCheckMode) -> hir::BlockCheckMode {
881 DefaultBlock => hir::DefaultBlock,
882 UnsafeBlock(u) => hir::UnsafeBlock(lower_unsafe_source(u)),
883 PushUnsafeBlock(u) => hir::PushUnsafeBlock(lower_unsafe_source(u)),
884 PopUnsafeBlock(u) => hir::PopUnsafeBlock(lower_unsafe_source(u)),
888 pub fn lower_pat_wild_kind(p: PatWildKind) -> hir::PatWildKind {
890 PatWildSingle => hir::PatWildSingle,
891 PatWildMulti => hir::PatWildMulti,
895 pub fn lower_binding_mode(b: &BindingMode) -> hir::BindingMode {
897 BindByRef(m) => hir::BindByRef(lower_mutability(m)),
898 BindByValue(m) => hir::BindByValue(lower_mutability(m)),
902 pub fn lower_struct_field_kind(s: &StructFieldKind) -> hir::StructFieldKind {
904 NamedField(ident, vis) => hir::NamedField(ident, lower_visibility(vis)),
905 UnnamedField(vis) => hir::UnnamedField(lower_visibility(vis)),
909 pub fn lower_unsafe_source(u: UnsafeSource) -> hir::UnsafeSource {
911 CompilerGenerated => hir::CompilerGenerated,
912 UserProvided => hir::UserProvided,
916 pub fn lower_impl_polarity(i: ImplPolarity) -> hir::ImplPolarity {
918 ImplPolarity::Positive => hir::ImplPolarity::Positive,
919 ImplPolarity::Negative => hir::ImplPolarity::Negative,
923 pub fn lower_trait_bound_modifier(f: TraitBoundModifier) -> hir::TraitBoundModifier {
925 TraitBoundModifier::None => hir::TraitBoundModifier::None,
926 TraitBoundModifier::Maybe => hir::TraitBoundModifier::Maybe,