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::{respan, 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.name, 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()
33 .map(|path_list_ident| {
35 node: match path_list_ident.node {
36 PathListIdent { id, name, rename } =>
40 rename: rename.map(|x| x.name),
42 PathListMod { id, rename } =>
45 rename: rename.map(|x| x.name),
48 span: path_list_ident.span,
58 pub fn lower_arm(arm: &Arm) -> hir::Arm {
60 attrs: arm.attrs.clone(),
61 pats: arm.pats.iter().map(|x| lower_pat(x)).collect(),
62 guard: arm.guard.as_ref().map(|ref x| lower_expr(x)),
63 body: lower_expr(&arm.body),
67 pub fn lower_decl(d: &Decl) -> P<hir::Decl> {
69 DeclLocal(ref l) => P(Spanned {
70 node: hir::DeclLocal(lower_local(l)),
73 DeclItem(ref it) => P(Spanned {
74 node: hir::DeclItem(lower_item(it)),
80 pub fn lower_ty_binding(b: &TypeBinding) -> P<hir::TypeBinding> {
89 pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
93 TyInfer => hir::TyInfer,
94 TyVec(ref ty) => hir::TyVec(lower_ty(ty)),
95 TyPtr(ref mt) => hir::TyPtr(lower_mt(mt)),
96 TyRptr(ref region, ref mt) => {
97 hir::TyRptr(lower_opt_lifetime(region), lower_mt(mt))
100 hir::TyBareFn(P(hir::BareFnTy {
101 lifetimes: lower_lifetime_defs(&f.lifetimes),
102 unsafety: lower_unsafety(f.unsafety),
104 decl: lower_fn_decl(&f.decl),
107 TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(ty)).collect()),
108 TyParen(ref ty) => hir::TyParen(lower_ty(ty)),
109 TyPath(ref qself, ref path) => {
110 let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
116 hir::TyPath(qself, lower_path(path))
118 TyObjectSum(ref ty, ref bounds) => {
119 hir::TyObjectSum(lower_ty(ty), lower_bounds(bounds))
121 TyFixedLengthVec(ref ty, ref e) => {
122 hir::TyFixedLengthVec(lower_ty(ty), lower_expr(e))
124 TyTypeof(ref expr) => {
125 hir::TyTypeof(lower_expr(expr))
127 TyPolyTraitRef(ref bounds) => {
128 hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(b)).collect())
130 TyMac(_) => panic!("TyMac should have been expanded by now."),
136 pub fn lower_foreign_mod(fm: &ForeignMod) -> hir::ForeignMod {
139 items: fm.items.iter().map(|x| lower_foreign_item(x)).collect(),
143 pub fn lower_variant(v: &Variant) -> P<hir::Variant> {
145 node: hir::Variant_ {
147 name: v.node.name.name,
148 attrs: v.node.attrs.clone(),
149 kind: match v.node.kind {
150 TupleVariantKind(ref variant_args) => {
151 hir::TupleVariantKind(variant_args.iter()
152 .map(|ref x| lower_variant_arg(x))
155 StructVariantKind(ref struct_def) => {
156 hir::StructVariantKind(lower_struct_def(struct_def))
159 disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(e)),
165 pub fn lower_path(p: &Path) -> hir::Path {
170 .map(|&PathSegment { identifier, ref parameters }| {
172 identifier: identifier,
173 parameters: lower_path_parameters(parameters),
181 pub fn lower_path_parameters(path_parameters: &PathParameters) -> hir::PathParameters {
182 match *path_parameters {
183 AngleBracketedParameters(ref data) =>
184 hir::AngleBracketedParameters(lower_angle_bracketed_parameter_data(data)),
185 ParenthesizedParameters(ref data) =>
186 hir::ParenthesizedParameters(lower_parenthesized_parameter_data(data)),
190 pub fn lower_angle_bracketed_parameter_data(data: &AngleBracketedParameterData)
191 -> hir::AngleBracketedParameterData {
192 let &AngleBracketedParameterData { ref lifetimes, ref types, ref bindings } = data;
193 hir::AngleBracketedParameterData {
194 lifetimes: lower_lifetimes(lifetimes),
195 types: types.iter().map(|ty| lower_ty(ty)).collect(),
196 bindings: bindings.iter().map(|b| lower_ty_binding(b)).collect(),
200 pub fn lower_parenthesized_parameter_data(data: &ParenthesizedParameterData)
201 -> hir::ParenthesizedParameterData {
202 let &ParenthesizedParameterData { ref inputs, ref output, span } = data;
203 hir::ParenthesizedParameterData {
204 inputs: inputs.iter().map(|ty| lower_ty(ty)).collect(),
205 output: output.as_ref().map(|ty| lower_ty(ty)),
210 pub fn lower_local(l: &Local) -> P<hir::Local> {
213 ty: l.ty.as_ref().map(|t| lower_ty(t)),
214 pat: lower_pat(&l.pat),
215 init: l.init.as_ref().map(|e| lower_expr(e)),
220 pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ {
222 SelfStatic => hir::SelfStatic,
223 SelfValue(v) => hir::SelfValue(v.name),
224 SelfRegion(ref lifetime, m, ident) => {
225 hir::SelfRegion(lower_opt_lifetime(lifetime),
229 SelfExplicit(ref typ, ident) => {
230 hir::SelfExplicit(lower_ty(typ), ident.name)
235 pub fn lower_mutability(m: Mutability) -> hir::Mutability {
237 MutMutable => hir::MutMutable,
238 MutImmutable => hir::MutImmutable,
242 pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf {
244 node: lower_explicit_self_underscore(&s.node),
249 pub fn lower_arg(arg: &Arg) -> hir::Arg {
252 pat: lower_pat(&arg.pat),
253 ty: lower_ty(&arg.ty),
257 pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
259 inputs: decl.inputs.iter().map(|x| lower_arg(x)).collect(),
260 output: match decl.output {
261 Return(ref ty) => hir::Return(lower_ty(ty)),
262 DefaultReturn(span) => hir::DefaultReturn(span),
263 NoReturn(span) => hir::NoReturn(span),
265 variadic: decl.variadic,
269 pub fn lower_ty_param_bound(tpb: &TyParamBound) -> hir::TyParamBound {
271 TraitTyParamBound(ref ty, modifier) => {
272 hir::TraitTyParamBound(lower_poly_trait_ref(ty),
273 lower_trait_bound_modifier(modifier))
275 RegionTyParamBound(ref lifetime) => hir::RegionTyParamBound(lower_lifetime(lifetime)),
279 pub fn lower_ty_param(tp: &TyParam) -> hir::TyParam {
283 bounds: lower_bounds(&tp.bounds),
284 default: tp.default.as_ref().map(|x| lower_ty(x)),
289 pub fn lower_ty_params(tps: &OwnedSlice<TyParam>) -> OwnedSlice<hir::TyParam> {
290 tps.iter().map(|tp| lower_ty_param(tp)).collect()
293 pub fn lower_lifetime(l: &Lifetime) -> hir::Lifetime {
301 pub fn lower_lifetime_def(l: &LifetimeDef) -> hir::LifetimeDef {
303 lifetime: lower_lifetime(&l.lifetime),
304 bounds: lower_lifetimes(&l.bounds),
308 pub fn lower_lifetimes(lts: &Vec<Lifetime>) -> Vec<hir::Lifetime> {
309 lts.iter().map(|l| lower_lifetime(l)).collect()
312 pub fn lower_lifetime_defs(lts: &Vec<LifetimeDef>) -> Vec<hir::LifetimeDef> {
313 lts.iter().map(|l| lower_lifetime_def(l)).collect()
316 pub fn lower_opt_lifetime(o_lt: &Option<Lifetime>) -> Option<hir::Lifetime> {
317 o_lt.as_ref().map(|lt| lower_lifetime(lt))
320 pub fn lower_generics(g: &Generics) -> hir::Generics {
322 ty_params: lower_ty_params(&g.ty_params),
323 lifetimes: lower_lifetime_defs(&g.lifetimes),
324 where_clause: lower_where_clause(&g.where_clause),
328 pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause {
331 predicates: wc.predicates
333 .map(|predicate| lower_where_predicate(predicate))
338 pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate {
340 WherePredicate::BoundPredicate(WhereBoundPredicate{ ref bound_lifetimes,
344 hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
345 bound_lifetimes: lower_lifetime_defs(bound_lifetimes),
346 bounded_ty: lower_ty(bounded_ty),
347 bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(),
351 WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
354 hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
356 lifetime: lower_lifetime(lifetime),
357 bounds: bounds.iter().map(|bound| lower_lifetime(bound)).collect(),
360 WherePredicate::EqPredicate(WhereEqPredicate{ id,
364 hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
366 path: lower_path(path),
374 pub fn lower_struct_def(sd: &StructDef) -> P<hir::StructDef> {
376 fields: sd.fields.iter().map(|f| lower_struct_field(f)).collect(),
381 pub fn lower_trait_ref(p: &TraitRef) -> hir::TraitRef {
383 path: lower_path(&p.path),
388 pub fn lower_poly_trait_ref(p: &PolyTraitRef) -> hir::PolyTraitRef {
390 bound_lifetimes: lower_lifetime_defs(&p.bound_lifetimes),
391 trait_ref: lower_trait_ref(&p.trait_ref),
396 pub fn lower_struct_field(f: &StructField) -> hir::StructField {
398 node: hir::StructField_ {
400 kind: lower_struct_field_kind(&f.node.kind),
401 ty: lower_ty(&f.node.ty),
402 attrs: f.node.attrs.clone(),
408 pub fn lower_field(f: &Field) -> hir::Field {
410 name: respan(f.ident.span, f.ident.node.name),
411 expr: lower_expr(&f.expr),
416 pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
418 ty: lower_ty(&mt.ty),
419 mutbl: lower_mutability(mt.mutbl),
423 pub fn lower_opt_bounds(b: &Option<OwnedSlice<TyParamBound>>)
424 -> Option<OwnedSlice<hir::TyParamBound>> {
425 b.as_ref().map(|ref bounds| lower_bounds(bounds))
428 fn lower_bounds(bounds: &TyParamBounds) -> hir::TyParamBounds {
429 bounds.iter().map(|bound| lower_ty_param_bound(bound)).collect()
432 fn lower_variant_arg(va: &VariantArg) -> hir::VariantArg {
435 ty: lower_ty(&va.ty),
439 pub fn lower_block(b: &Block) -> P<hir::Block> {
442 stmts: b.stmts.iter().map(|s| lower_stmt(s)).collect(),
443 expr: b.expr.as_ref().map(|ref x| lower_expr(x)),
444 rules: lower_block_check_mode(&b.rules),
449 pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
451 ItemExternCrate(string) => hir::ItemExternCrate(string),
452 ItemUse(ref view_path) => {
453 hir::ItemUse(lower_view_path(view_path))
455 ItemStatic(ref t, m, ref e) => {
456 hir::ItemStatic(lower_ty(t), lower_mutability(m), lower_expr(e))
458 ItemConst(ref t, ref e) => {
459 hir::ItemConst(lower_ty(t), lower_expr(e))
461 ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
462 hir::ItemFn(lower_fn_decl(decl),
463 lower_unsafety(unsafety),
464 lower_constness(constness),
466 lower_generics(generics),
469 ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
470 ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)),
471 ItemTy(ref t, ref generics) => {
472 hir::ItemTy(lower_ty(t), lower_generics(generics))
474 ItemEnum(ref enum_definition, ref generics) => {
475 hir::ItemEnum(hir::EnumDef {
476 variants: enum_definition.variants
478 .map(|x| lower_variant(x))
481 lower_generics(generics))
483 ItemStruct(ref struct_def, ref generics) => {
484 let struct_def = lower_struct_def(struct_def);
485 hir::ItemStruct(struct_def, lower_generics(generics))
487 ItemDefaultImpl(unsafety, ref trait_ref) => {
488 hir::ItemDefaultImpl(lower_unsafety(unsafety), lower_trait_ref(trait_ref))
490 ItemImpl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => {
491 let new_impl_items = impl_items.iter().map(|item| lower_impl_item(item)).collect();
492 let ifce = ifce.as_ref().map(|trait_ref| lower_trait_ref(trait_ref));
493 hir::ItemImpl(lower_unsafety(unsafety),
494 lower_impl_polarity(polarity),
495 lower_generics(generics),
500 ItemTrait(unsafety, ref generics, ref bounds, ref items) => {
501 let bounds = lower_bounds(bounds);
502 let items = items.iter().map(|item| lower_trait_item(item)).collect();
503 hir::ItemTrait(lower_unsafety(unsafety),
504 lower_generics(generics),
508 ItemMac(_) => panic!("Shouldn't still be around"),
512 pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
516 attrs: i.attrs.clone(),
518 ConstTraitItem(ref ty, ref default) => {
519 hir::ConstTraitItem(lower_ty(ty),
520 default.as_ref().map(|x| lower_expr(x)))
522 MethodTraitItem(ref sig, ref body) => {
523 hir::MethodTraitItem(lower_method_sig(sig),
524 body.as_ref().map(|x| lower_block(x)))
526 TypeTraitItem(ref bounds, ref default) => {
527 hir::TypeTraitItem(lower_bounds(bounds),
528 default.as_ref().map(|x| lower_ty(x)))
535 pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
539 attrs: i.attrs.clone(),
540 vis: lower_visibility(i.vis),
542 ConstImplItem(ref ty, ref expr) => {
543 hir::ConstImplItem(lower_ty(ty), lower_expr(expr))
545 MethodImplItem(ref sig, ref body) => {
546 hir::MethodImplItem(lower_method_sig(sig), lower_block(body))
548 TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)),
549 MacImplItem(..) => panic!("Shouldn't exist any more"),
555 pub fn lower_mod(m: &Mod) -> hir::Mod {
558 items: m.items.iter().map(|x| lower_item(x)).collect(),
562 pub fn lower_crate(c: &Crate) -> hir::Crate {
564 module: lower_mod(&c.module),
565 attrs: c.attrs.clone(),
566 config: c.config.clone(),
568 exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(m)).collect(),
572 pub fn lower_macro_def(m: &MacroDef) -> hir::MacroDef {
575 attrs: m.attrs.clone(),
578 imported_from: m.imported_from.map(|x| x.name),
580 use_locally: m.use_locally,
581 allow_internal_unstable: m.allow_internal_unstable,
582 body: m.body.clone(),
586 // fold one item into possibly many items
587 pub fn lower_item(i: &Item) -> P<hir::Item> {
588 P(lower_item_simple(i))
591 // fold one item into exactly one item
592 pub fn lower_item_simple(i: &Item) -> hir::Item {
593 let node = lower_item_underscore(&i.node);
598 attrs: i.attrs.clone(),
600 vis: lower_visibility(i.vis),
605 pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
609 attrs: i.attrs.clone(),
611 ForeignItemFn(ref fdec, ref generics) => {
612 hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics))
614 ForeignItemStatic(ref t, m) => {
615 hir::ForeignItemStatic(lower_ty(t), m)
618 vis: lower_visibility(i.vis),
623 pub fn lower_method_sig(sig: &MethodSig) -> hir::MethodSig {
625 generics: lower_generics(&sig.generics),
627 explicit_self: lower_explicit_self(&sig.explicit_self),
628 unsafety: lower_unsafety(sig.unsafety),
629 constness: lower_constness(sig.constness),
630 decl: lower_fn_decl(&sig.decl),
634 pub fn lower_unsafety(u: Unsafety) -> hir::Unsafety {
636 Unsafety::Unsafe => hir::Unsafety::Unsafe,
637 Unsafety::Normal => hir::Unsafety::Normal,
641 pub fn lower_constness(c: Constness) -> hir::Constness {
643 Constness::Const => hir::Constness::Const,
644 Constness::NotConst => hir::Constness::NotConst,
648 pub fn lower_unop(u: UnOp) -> hir::UnOp {
650 UnDeref => hir::UnDeref,
656 pub fn lower_binop(b: BinOp) -> hir::BinOp {
666 BiBitXor => hir::BiBitXor,
667 BiBitAnd => hir::BiBitAnd,
668 BiBitOr => hir::BiBitOr,
682 pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
686 PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)),
687 PatIdent(ref binding_mode, pth1, ref sub) => {
688 hir::PatIdent(lower_binding_mode(binding_mode),
690 sub.as_ref().map(|x| lower_pat(x)))
692 PatLit(ref e) => hir::PatLit(lower_expr(e)),
693 PatEnum(ref pth, ref pats) => {
694 hir::PatEnum(lower_path(pth),
695 pats.as_ref().map(|pats| pats.iter().map(|x| lower_pat(x)).collect()))
697 PatQPath(ref qself, ref pth) => {
698 let qself = hir::QSelf {
699 ty: lower_ty(&qself.ty),
700 position: qself.position,
702 hir::PatQPath(qself, lower_path(pth))
704 PatStruct(ref pth, ref fields, etc) => {
705 let pth = lower_path(pth);
706 let fs = fields.iter()
710 node: hir::FieldPat {
711 name: f.node.ident.name,
712 pat: lower_pat(&f.node.pat),
713 is_shorthand: f.node.is_shorthand,
718 hir::PatStruct(pth, fs, etc)
720 PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()),
721 PatBox(ref inner) => hir::PatBox(lower_pat(inner)),
722 PatRegion(ref inner, mutbl) =>
723 hir::PatRegion(lower_pat(inner), lower_mutability(mutbl)),
724 PatRange(ref e1, ref e2) => {
725 hir::PatRange(lower_expr(e1), lower_expr(e2))
727 PatVec(ref before, ref slice, ref after) => {
728 hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(),
729 slice.as_ref().map(|x| lower_pat(x)),
730 after.iter().map(|x| lower_pat(x)).collect())
732 PatMac(_) => panic!("Shouldn't exist here"),
738 pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
743 hir::ExprBox(lower_expr(e))
745 ExprVec(ref exprs) => {
746 hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
748 ExprRepeat(ref expr, ref count) => {
749 hir::ExprRepeat(lower_expr(expr), lower_expr(count))
751 ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
752 ExprCall(ref f, ref args) => {
753 hir::ExprCall(lower_expr(f),
754 args.iter().map(|x| lower_expr(x)).collect())
756 ExprMethodCall(i, ref tps, ref args) => {
757 hir::ExprMethodCall(respan(i.span, i.node.name),
758 tps.iter().map(|x| lower_ty(x)).collect(),
759 args.iter().map(|x| lower_expr(x)).collect())
761 ExprBinary(binop, ref lhs, ref rhs) => {
762 hir::ExprBinary(lower_binop(binop), lower_expr(lhs), lower_expr(rhs))
764 ExprUnary(op, ref ohs) => {
765 hir::ExprUnary(lower_unop(op), lower_expr(ohs))
767 ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
768 ExprCast(ref expr, ref ty) => {
769 hir::ExprCast(lower_expr(expr), lower_ty(ty))
771 ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
772 ExprIf(ref cond, ref tr, ref fl) => {
773 hir::ExprIf(lower_expr(cond),
775 fl.as_ref().map(|x| lower_expr(x)))
777 ExprWhile(ref cond, ref body, opt_ident) => {
778 hir::ExprWhile(lower_expr(cond), lower_block(body), opt_ident)
780 ExprLoop(ref body, opt_ident) => {
781 hir::ExprLoop(lower_block(body), opt_ident)
783 ExprMatch(ref expr, ref arms, ref source) => {
784 hir::ExprMatch(lower_expr(expr),
785 arms.iter().map(|x| lower_arm(x)).collect(),
786 lower_match_source(source))
788 ExprClosure(capture_clause, ref decl, ref body) => {
789 hir::ExprClosure(lower_capture_clause(capture_clause),
793 ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
794 ExprAssign(ref el, ref er) => {
795 hir::ExprAssign(lower_expr(el), lower_expr(er))
797 ExprAssignOp(op, ref el, ref er) => {
798 hir::ExprAssignOp(lower_binop(op), lower_expr(el), lower_expr(er))
800 ExprField(ref el, ident) => {
801 hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
803 ExprTupField(ref el, ident) => {
804 hir::ExprTupField(lower_expr(el), ident)
806 ExprIndex(ref el, ref er) => {
807 hir::ExprIndex(lower_expr(el), lower_expr(er))
809 ExprRange(ref e1, ref e2) => {
810 hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
811 e2.as_ref().map(|x| lower_expr(x)))
813 ExprPath(ref qself, ref path) => {
814 let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
820 hir::ExprPath(qself, lower_path(path))
822 ExprBreak(opt_ident) => hir::ExprBreak(opt_ident),
823 ExprAgain(opt_ident) => hir::ExprAgain(opt_ident),
824 ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(x))),
825 ExprInlineAsm(InlineAsm {
835 }) => hir::ExprInlineAsm(hir::InlineAsm {
836 inputs: inputs.iter()
837 .map(|&(ref c, ref input)| (c.clone(), lower_expr(input)))
839 outputs: outputs.iter()
840 .map(|&(ref c, ref out, ref is_rw)| {
841 (c.clone(), lower_expr(out), *is_rw)
845 asm_str_style: asm_str_style,
846 clobbers: clobbers.clone(),
848 alignstack: alignstack,
852 ExprStruct(ref path, ref fields, ref maybe_expr) => {
853 hir::ExprStruct(lower_path(path),
854 fields.iter().map(|x| lower_field(x)).collect(),
855 maybe_expr.as_ref().map(|x| lower_expr(x)))
857 ExprParen(ref ex) => {
858 return lower_expr(ex);
864 ExprMac(_) => panic!("Shouldn't exist here"),
870 pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
872 StmtDecl(ref d, id) => {
874 node: hir::StmtDecl(lower_decl(d), id),
878 StmtExpr(ref e, id) => {
880 node: hir::StmtExpr(lower_expr(e), id),
884 StmtSemi(ref e, id) => {
886 node: hir::StmtSemi(lower_expr(e), id),
890 StmtMac(..) => panic!("Shouldn't exist here"),
894 pub fn lower_match_source(m: &MatchSource) -> hir::MatchSource {
896 MatchSource::Normal => hir::MatchSource::Normal,
897 MatchSource::IfLetDesugar { contains_else_clause } => {
898 hir::MatchSource::IfLetDesugar { contains_else_clause: contains_else_clause }
900 MatchSource::WhileLetDesugar => hir::MatchSource::WhileLetDesugar,
901 MatchSource::ForLoopDesugar => hir::MatchSource::ForLoopDesugar,
905 pub fn lower_capture_clause(c: CaptureClause) -> hir::CaptureClause {
907 CaptureByValue => hir::CaptureByValue,
908 CaptureByRef => hir::CaptureByRef,
912 pub fn lower_visibility(v: Visibility) -> hir::Visibility {
914 Public => hir::Public,
915 Inherited => hir::Inherited,
919 pub fn lower_block_check_mode(b: &BlockCheckMode) -> hir::BlockCheckMode {
921 DefaultBlock => hir::DefaultBlock,
922 UnsafeBlock(u) => hir::UnsafeBlock(lower_unsafe_source(u)),
923 PushUnsafeBlock(u) => hir::PushUnsafeBlock(lower_unsafe_source(u)),
924 PopUnsafeBlock(u) => hir::PopUnsafeBlock(lower_unsafe_source(u)),
928 pub fn lower_pat_wild_kind(p: PatWildKind) -> hir::PatWildKind {
930 PatWildSingle => hir::PatWildSingle,
931 PatWildMulti => hir::PatWildMulti,
935 pub fn lower_binding_mode(b: &BindingMode) -> hir::BindingMode {
937 BindByRef(m) => hir::BindByRef(lower_mutability(m)),
938 BindByValue(m) => hir::BindByValue(lower_mutability(m)),
942 pub fn lower_struct_field_kind(s: &StructFieldKind) -> hir::StructFieldKind {
944 NamedField(ident, vis) => hir::NamedField(ident.name, lower_visibility(vis)),
945 UnnamedField(vis) => hir::UnnamedField(lower_visibility(vis)),
949 pub fn lower_unsafe_source(u: UnsafeSource) -> hir::UnsafeSource {
951 CompilerGenerated => hir::CompilerGenerated,
952 UserProvided => hir::UserProvided,
956 pub fn lower_impl_polarity(i: ImplPolarity) -> hir::ImplPolarity {
958 ImplPolarity::Positive => hir::ImplPolarity::Positive,
959 ImplPolarity::Negative => hir::ImplPolarity::Negative,
963 pub fn lower_trait_bound_modifier(f: TraitBoundModifier) -> hir::TraitBoundModifier {
965 TraitBoundModifier::None => hir::TraitBoundModifier::None,
966 TraitBoundModifier::Maybe => hir::TraitBoundModifier::Maybe,