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)),
155 pub fn lower_path(p: &Path) -> hir::Path {
158 segments: p.segments.iter().map(|&PathSegment {identifier, ref parameters}|
160 identifier: identifier,
161 parameters: lower_path_parameters(parameters),
167 pub fn lower_path_parameters(path_parameters: &PathParameters) -> hir::PathParameters {
168 match *path_parameters {
169 AngleBracketedParameters(ref data) =>
170 hir::AngleBracketedParameters(lower_angle_bracketed_parameter_data(data)),
171 ParenthesizedParameters(ref data) =>
172 hir::ParenthesizedParameters(lower_parenthesized_parameter_data(data)),
176 pub fn lower_angle_bracketed_parameter_data(data: &AngleBracketedParameterData)
177 -> hir::AngleBracketedParameterData {
178 let &AngleBracketedParameterData { ref lifetimes, ref types, ref bindings } = data;
179 hir::AngleBracketedParameterData {
180 lifetimes: lower_lifetimes(lifetimes),
181 types: types.iter().map(|ty| lower_ty(ty)).collect(),
182 bindings: bindings.iter().map(|b| lower_ty_binding(b)).collect(),
186 pub fn lower_parenthesized_parameter_data(data: &ParenthesizedParameterData)
187 -> hir::ParenthesizedParameterData {
188 let &ParenthesizedParameterData { ref inputs, ref output, span } = data;
189 hir::ParenthesizedParameterData {
190 inputs: inputs.iter().map(|ty| lower_ty(ty)).collect(),
191 output: output.as_ref().map(|ty| lower_ty(ty)),
196 pub fn lower_local(l: &Local) -> P<hir::Local> {
199 ty: l.ty.as_ref().map(|t| lower_ty(t)),
200 pat: lower_pat(&l.pat),
201 init: l.init.as_ref().map(|e| lower_expr(e)),
206 pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ {
208 SelfStatic => hir::SelfStatic,
209 SelfValue(v) => hir::SelfValue(v),
210 SelfRegion(ref lifetime, m, ident) => {
211 hir::SelfRegion(lower_opt_lifetime(lifetime), lower_mutability(m), ident)
213 SelfExplicit(ref typ, ident) => {
214 hir::SelfExplicit(lower_ty(typ), ident)
219 pub fn lower_mutability(m: Mutability) -> hir::Mutability {
221 MutMutable => hir::MutMutable,
222 MutImmutable => hir::MutImmutable,
226 pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf {
227 Spanned { node: lower_explicit_self_underscore(&s.node), span: s.span }
230 pub fn lower_arg(arg: &Arg) -> hir::Arg {
231 hir::Arg { id: arg.id, pat: lower_pat(&arg.pat), ty: lower_ty(&arg.ty) }
234 pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
236 inputs: decl.inputs.iter().map(|x| lower_arg(x)).collect(),
237 output: match decl.output {
238 Return(ref ty) => hir::Return(lower_ty(ty)),
239 DefaultReturn(span) => hir::DefaultReturn(span),
240 NoReturn(span) => hir::NoReturn(span)
242 variadic: decl.variadic,
246 pub fn lower_ty_param_bound(tpb: &TyParamBound) -> hir::TyParamBound {
248 TraitTyParamBound(ref ty, modifier) => {
249 hir::TraitTyParamBound(lower_poly_trait_ref(ty), lower_trait_bound_modifier(modifier))
251 RegionTyParamBound(ref lifetime) => hir::RegionTyParamBound(lower_lifetime(lifetime)),
255 pub fn lower_ty_param(tp: &TyParam) -> hir::TyParam {
259 bounds: lower_bounds(&tp.bounds),
260 default: tp.default.as_ref().map(|x| lower_ty(x)),
265 pub fn lower_ty_params(tps: &OwnedSlice<TyParam>) -> OwnedSlice<hir::TyParam> {
266 tps.iter().map(|tp| lower_ty_param(tp)).collect()
269 pub fn lower_lifetime(l: &Lifetime) -> hir::Lifetime {
270 hir::Lifetime { id: l.id, name: l.name, span: l.span }
273 pub fn lower_lifetime_def(l: &LifetimeDef) -> hir::LifetimeDef {
274 hir::LifetimeDef { lifetime: lower_lifetime(&l.lifetime), bounds: lower_lifetimes(&l.bounds) }
277 pub fn lower_lifetimes(lts: &Vec<Lifetime>) -> Vec<hir::Lifetime> {
278 lts.iter().map(|l| lower_lifetime(l)).collect()
281 pub fn lower_lifetime_defs(lts: &Vec<LifetimeDef>) -> Vec<hir::LifetimeDef> {
282 lts.iter().map(|l| lower_lifetime_def(l)).collect()
285 pub fn lower_opt_lifetime(o_lt: &Option<Lifetime>) -> Option<hir::Lifetime> {
286 o_lt.as_ref().map(|lt| lower_lifetime(lt))
289 pub fn lower_generics(g: &Generics) -> hir::Generics {
291 ty_params: lower_ty_params(&g.ty_params),
292 lifetimes: lower_lifetime_defs(&g.lifetimes),
293 where_clause: lower_where_clause(&g.where_clause),
297 pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause {
300 predicates: wc.predicates.iter().map(|predicate|
301 lower_where_predicate(predicate)).collect(),
305 pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate {
307 WherePredicate::BoundPredicate(WhereBoundPredicate{ ref bound_lifetimes,
311 hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
312 bound_lifetimes: lower_lifetime_defs(bound_lifetimes),
313 bounded_ty: lower_ty(bounded_ty),
314 bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(),
318 WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
321 hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
323 lifetime: lower_lifetime(lifetime),
324 bounds: bounds.iter().map(|bound| lower_lifetime(bound)).collect()
327 WherePredicate::EqPredicate(WhereEqPredicate{ id,
331 hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{
333 path: lower_path(path),
341 pub fn lower_struct_def(sd: &StructDef) -> P<hir::StructDef> {
343 fields: sd.fields.iter().map(|f| lower_struct_field(f)).collect(),
348 pub fn lower_trait_ref(p: &TraitRef) -> hir::TraitRef {
349 hir::TraitRef { path: lower_path(&p.path), ref_id: p.ref_id }
352 pub fn lower_poly_trait_ref(p: &PolyTraitRef) -> hir::PolyTraitRef {
354 bound_lifetimes: lower_lifetime_defs(&p.bound_lifetimes),
355 trait_ref: lower_trait_ref(&p.trait_ref),
360 pub fn lower_struct_field(f: &StructField) -> hir::StructField {
362 node: hir::StructField_ {
364 kind: lower_struct_field_kind(&f.node.kind),
365 ty: lower_ty(&f.node.ty),
366 attrs: f.node.attrs.clone(),
372 pub fn lower_field(f: &Field) -> hir::Field {
373 hir::Field { ident: f.ident, expr: lower_expr(&f.expr), span: f.span }
376 pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
377 hir::MutTy { ty: lower_ty(&mt.ty), mutbl: lower_mutability(mt.mutbl) }
380 pub fn lower_opt_bounds(b: &Option<OwnedSlice<TyParamBound>>)
381 -> Option<OwnedSlice<hir::TyParamBound>> {
382 b.as_ref().map(|ref bounds| lower_bounds(bounds))
385 fn lower_bounds(bounds: &TyParamBounds) -> hir::TyParamBounds {
386 bounds.iter().map(|bound| lower_ty_param_bound(bound)).collect()
389 fn lower_variant_arg(va: &VariantArg) -> hir::VariantArg {
390 hir::VariantArg { id: va.id, ty: lower_ty(&va.ty) }
393 pub fn lower_block(b: &Block) -> P<hir::Block> {
396 stmts: b.stmts.iter().map(|s| lower_stmt(s)).collect(),
397 expr: b.expr.as_ref().map(|ref x| lower_expr(x)),
398 rules: lower_block_check_mode(&b.rules),
403 pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
405 ItemExternCrate(string) => hir::ItemExternCrate(string),
406 ItemUse(ref view_path) => {
407 hir::ItemUse(lower_view_path(view_path))
409 ItemStatic(ref t, m, ref e) => {
410 hir::ItemStatic(lower_ty(t), lower_mutability(m), lower_expr(e))
412 ItemConst(ref t, ref e) => {
413 hir::ItemConst(lower_ty(t), lower_expr(e))
415 ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
418 lower_unsafety(unsafety),
419 lower_constness(constness),
421 lower_generics(generics),
425 ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
426 ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)),
427 ItemTy(ref t, ref generics) => {
428 hir::ItemTy(lower_ty(t), lower_generics(generics))
430 ItemEnum(ref enum_definition, ref generics) => {
433 variants: enum_definition.variants.iter().map(|x| lower_variant(x)).collect(),
435 lower_generics(generics))
437 ItemStruct(ref struct_def, ref generics) => {
438 let struct_def = lower_struct_def(struct_def);
439 hir::ItemStruct(struct_def, lower_generics(generics))
441 ItemDefaultImpl(unsafety, ref trait_ref) => {
442 hir::ItemDefaultImpl(lower_unsafety(unsafety), lower_trait_ref(trait_ref))
444 ItemImpl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => {
445 let new_impl_items = impl_items.iter().map(|item| lower_impl_item(item)).collect();
446 let ifce = ifce.as_ref().map(|trait_ref| lower_trait_ref(trait_ref));
447 hir::ItemImpl(lower_unsafety(unsafety),
448 lower_impl_polarity(polarity),
449 lower_generics(generics),
454 ItemTrait(unsafety, ref generics, ref bounds, ref items) => {
455 let bounds = lower_bounds(bounds);
456 let items = items.iter().map(|item| lower_trait_item(item)).collect();
457 hir::ItemTrait(lower_unsafety(unsafety),
458 lower_generics(generics),
462 ItemMac(_) => panic!("Shouldn't still be around"),
466 pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
470 attrs: i.attrs.clone(),
472 ConstTraitItem(ref ty, ref default) => {
473 hir::ConstTraitItem(lower_ty(ty),
474 default.as_ref().map(|x| lower_expr(x)))
476 MethodTraitItem(ref sig, ref body) => {
477 hir::MethodTraitItem(lower_method_sig(sig),
478 body.as_ref().map(|x| lower_block(x)))
480 TypeTraitItem(ref bounds, ref default) => {
481 hir::TypeTraitItem(lower_bounds(bounds),
482 default.as_ref().map(|x| lower_ty(x)))
489 pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
493 attrs: i.attrs.clone(),
494 vis: lower_visibility(i.vis),
496 ConstImplItem(ref ty, ref expr) => {
497 hir::ConstImplItem(lower_ty(ty), lower_expr(expr))
499 MethodImplItem(ref sig, ref body) => {
500 hir::MethodImplItem(lower_method_sig(sig),
503 TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)),
504 MacImplItem(..) => panic!("Shouldn't exist any more"),
510 pub fn lower_mod(m: &Mod) -> hir::Mod {
511 hir::Mod { inner: m.inner, items: m.items.iter().map(|x| lower_item(x)).collect() }
514 pub fn lower_crate(c: &Crate) -> hir::Crate {
516 module: lower_mod(&c.module),
517 attrs: c.attrs.clone(),
518 config: c.config.clone(),
520 exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(m)).collect(),
524 pub fn lower_macro_def(m: &MacroDef) -> hir::MacroDef {
527 attrs: m.attrs.clone(),
530 imported_from: m.imported_from,
532 use_locally: m.use_locally,
533 allow_internal_unstable: m.allow_internal_unstable,
534 body: m.body.clone(),
538 // fold one item into possibly many items
539 pub fn lower_item(i: &Item) -> P<hir::Item> {
540 P(lower_item_simple(i))
543 // fold one item into exactly one item
544 pub fn lower_item_simple(i: &Item) -> hir::Item {
545 let node = lower_item_underscore(&i.node);
550 attrs: i.attrs.clone(),
552 vis: lower_visibility(i.vis),
557 pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
561 attrs: i.attrs.clone(),
563 ForeignItemFn(ref fdec, ref generics) => {
564 hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics))
566 ForeignItemStatic(ref t, m) => {
567 hir::ForeignItemStatic(lower_ty(t), m)
570 vis: lower_visibility(i.vis),
575 pub fn lower_method_sig(sig: &MethodSig) -> hir::MethodSig {
577 generics: lower_generics(&sig.generics),
579 explicit_self: lower_explicit_self(&sig.explicit_self),
580 unsafety: lower_unsafety(sig.unsafety),
581 constness: lower_constness(sig.constness),
582 decl: lower_fn_decl(&sig.decl),
586 pub fn lower_unsafety(u: Unsafety) -> hir::Unsafety {
588 Unsafety::Unsafe => hir::Unsafety::Unsafe,
589 Unsafety::Normal => hir::Unsafety::Normal,
593 pub fn lower_constness(c: Constness) -> hir::Constness {
595 Constness::Const => hir::Constness::Const,
596 Constness::NotConst => hir::Constness::NotConst,
600 pub fn lower_unop(u: UnOp) -> hir::UnOp {
602 UnUniq => hir::UnUniq,
603 UnDeref => hir::UnDeref,
609 pub fn lower_binop(b: BinOp) -> hir::BinOp {
619 BiBitXor => hir::BiBitXor,
620 BiBitAnd => hir::BiBitAnd,
621 BiBitOr => hir::BiBitOr,
635 pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
639 PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)),
640 PatIdent(ref binding_mode, pth1, ref sub) => {
641 hir::PatIdent(lower_binding_mode(binding_mode),
643 sub.as_ref().map(|x| lower_pat(x)))
645 PatLit(ref e) => hir::PatLit(lower_expr(e)),
646 PatEnum(ref pth, ref pats) => {
647 hir::PatEnum(lower_path(pth),
648 pats.as_ref().map(|pats| pats.iter().map(|x| lower_pat(x)).collect()))
650 PatQPath(ref qself, ref pth) => {
651 let qself = hir::QSelf {
652 ty: lower_ty(&qself.ty),
653 position: qself.position,
655 hir::PatQPath(qself, lower_path(pth))
657 PatStruct(ref pth, ref fields, etc) => {
658 let pth = lower_path(pth);
659 let fs = fields.iter().map(|f| {
660 Spanned { span: f.span,
661 node: hir::FieldPat {
663 pat: lower_pat(&f.node.pat),
664 is_shorthand: f.node.is_shorthand,
667 hir::PatStruct(pth, fs, etc)
669 PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()),
670 PatBox(ref inner) => hir::PatBox(lower_pat(inner)),
671 PatRegion(ref inner, mutbl) => hir::PatRegion(lower_pat(inner),
672 lower_mutability(mutbl)),
673 PatRange(ref e1, ref e2) => {
674 hir::PatRange(lower_expr(e1), lower_expr(e2))
676 PatVec(ref before, ref slice, ref after) => {
677 hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(),
678 slice.as_ref().map(|x| lower_pat(x)),
679 after.iter().map(|x| lower_pat(x)).collect())
681 PatMac(_) => panic!("Shouldn't exist here"),
687 pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
691 ExprBox(ref p, ref e) => {
692 hir::ExprBox(p.as_ref().map(|e| lower_expr(e)), lower_expr(e))
694 ExprVec(ref exprs) => {
695 hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
697 ExprRepeat(ref expr, ref count) => {
698 hir::ExprRepeat(lower_expr(expr), lower_expr(count))
700 ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
701 ExprCall(ref f, ref args) => {
702 hir::ExprCall(lower_expr(f),
703 args.iter().map(|x| lower_expr(x)).collect())
705 ExprMethodCall(i, ref tps, ref args) => {
708 tps.iter().map(|x| lower_ty(x)).collect(),
709 args.iter().map(|x| lower_expr(x)).collect())
711 ExprBinary(binop, ref lhs, ref rhs) => {
712 hir::ExprBinary(lower_binop(binop),
716 ExprUnary(op, ref ohs) => {
717 hir::ExprUnary(lower_unop(op), lower_expr(ohs))
719 ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
720 ExprCast(ref expr, ref ty) => {
721 hir::ExprCast(lower_expr(expr), lower_ty(ty))
723 ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
724 ExprIf(ref cond, ref tr, ref fl) => {
725 hir::ExprIf(lower_expr(cond),
727 fl.as_ref().map(|x| lower_expr(x)))
729 ExprWhile(ref cond, ref body, opt_ident) => {
730 hir::ExprWhile(lower_expr(cond),
734 ExprLoop(ref body, opt_ident) => {
735 hir::ExprLoop(lower_block(body),
738 ExprMatch(ref expr, ref arms, ref source) => {
739 hir::ExprMatch(lower_expr(expr),
740 arms.iter().map(|x| lower_arm(x)).collect(),
741 lower_match_source(source))
743 ExprClosure(capture_clause, ref decl, ref body) => {
744 hir::ExprClosure(lower_capture_clause(capture_clause),
748 ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
749 ExprAssign(ref el, ref er) => {
750 hir::ExprAssign(lower_expr(el), lower_expr(er))
752 ExprAssignOp(op, ref el, ref er) => {
753 hir::ExprAssignOp(lower_binop(op),
757 ExprField(ref el, ident) => {
758 hir::ExprField(lower_expr(el), ident)
760 ExprTupField(ref el, ident) => {
761 hir::ExprTupField(lower_expr(el), ident)
763 ExprIndex(ref el, ref er) => {
764 hir::ExprIndex(lower_expr(el), lower_expr(er))
766 ExprRange(ref e1, ref e2) => {
767 hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
768 e2.as_ref().map(|x| lower_expr(x)))
770 ExprPath(ref qself, ref path) => {
771 let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
777 hir::ExprPath(qself, lower_path(path))
779 ExprBreak(opt_ident) => hir::ExprBreak(opt_ident),
780 ExprAgain(opt_ident) => hir::ExprAgain(opt_ident),
781 ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(x))),
782 ExprInlineAsm(InlineAsm {
792 }) => hir::ExprInlineAsm(hir::InlineAsm {
793 inputs: inputs.iter().map(|&(ref c, ref input)| {
794 (c.clone(), lower_expr(input))
796 outputs: outputs.iter().map(|&(ref c, ref out, ref is_rw)| {
797 (c.clone(), lower_expr(out), *is_rw)
800 asm_str_style: asm_str_style,
801 clobbers: clobbers.clone(),
803 alignstack: alignstack,
807 ExprStruct(ref path, ref fields, ref maybe_expr) => {
808 hir::ExprStruct(lower_path(path),
809 fields.iter().map(|x| lower_field(x)).collect(),
810 maybe_expr.as_ref().map(|x| lower_expr(x)))
812 ExprParen(ref ex) => {
813 return lower_expr(ex);
818 ExprMac(_) => panic!("Shouldn't exist here"),
824 pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
826 StmtDecl(ref d, id) => {
828 node: hir::StmtDecl(lower_decl(d), id),
832 StmtExpr(ref e, id) => {
834 node: hir::StmtExpr(lower_expr(e), id),
838 StmtSemi(ref e, id) => {
840 node: hir::StmtSemi(lower_expr(e), id),
844 StmtMac(..) => panic!("Shouldn't exist here")
848 pub fn lower_match_source(m: &MatchSource) -> hir::MatchSource {
850 MatchSource::Normal => hir::MatchSource::Normal,
851 MatchSource::IfLetDesugar { contains_else_clause } => {
852 hir::MatchSource::IfLetDesugar { contains_else_clause: contains_else_clause }
854 MatchSource::WhileLetDesugar => hir::MatchSource::WhileLetDesugar,
855 MatchSource::ForLoopDesugar => hir::MatchSource::ForLoopDesugar,
859 pub fn lower_capture_clause(c: CaptureClause) -> hir::CaptureClause {
861 CaptureByValue => hir::CaptureByValue,
862 CaptureByRef => hir::CaptureByRef,
866 pub fn lower_visibility(v: Visibility) -> hir::Visibility {
868 Public => hir::Public,
869 Inherited => hir::Inherited,
873 pub fn lower_block_check_mode(b: &BlockCheckMode) -> hir::BlockCheckMode {
875 DefaultBlock => hir::DefaultBlock,
876 UnsafeBlock(u) => hir::UnsafeBlock(lower_unsafe_source(u)),
877 PushUnsafeBlock(u) => hir::PushUnsafeBlock(lower_unsafe_source(u)),
878 PopUnsafeBlock(u) => hir::PopUnsafeBlock(lower_unsafe_source(u)),
882 pub fn lower_pat_wild_kind(p: PatWildKind) -> hir::PatWildKind {
884 PatWildSingle => hir::PatWildSingle,
885 PatWildMulti => hir::PatWildMulti,
889 pub fn lower_binding_mode(b: &BindingMode) -> hir::BindingMode {
891 BindByRef(m) => hir::BindByRef(lower_mutability(m)),
892 BindByValue(m) => hir::BindByValue(lower_mutability(m)),
896 pub fn lower_struct_field_kind(s: &StructFieldKind) -> hir::StructFieldKind {
898 NamedField(ident, vis) => hir::NamedField(ident, lower_visibility(vis)),
899 UnnamedField(vis) => hir::UnnamedField(lower_visibility(vis)),
903 pub fn lower_unsafe_source(u: UnsafeSource) -> hir::UnsafeSource {
905 CompilerGenerated => hir::CompilerGenerated,
906 UserProvided => hir::UserProvided,
910 pub fn lower_impl_polarity(i: ImplPolarity) -> hir::ImplPolarity {
912 ImplPolarity::Positive => hir::ImplPolarity::Positive,
913 ImplPolarity::Negative => hir::ImplPolarity::Negative,
917 pub fn lower_trait_bound_modifier(f: TraitBoundModifier) -> hir::TraitBoundModifier {
919 TraitBoundModifier::None => hir::TraitBoundModifier::None,
920 TraitBoundModifier::Maybe => hir::TraitBoundModifier::Maybe,