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().map(|path_list_ident| {
34 node: match path_list_ident.node {
35 PathListIdent { id, name, rename } =>
39 rename: rename.map(|x| x.name),
41 PathListMod { id, rename } =>
44 rename: rename.map(|x| x.name)
47 span: path_list_ident.span
56 pub fn lower_arm(arm: &Arm) -> hir::Arm {
58 attrs: arm.attrs.clone(),
59 pats: arm.pats.iter().map(|x| lower_pat(x)).collect(),
60 guard: arm.guard.as_ref().map(|ref x| lower_expr(x)),
61 body: lower_expr(&arm.body),
65 pub fn lower_decl(d: &Decl) -> P<hir::Decl> {
67 DeclLocal(ref l) => P(Spanned {
68 node: hir::DeclLocal(lower_local(l)),
71 DeclItem(ref it) => P(Spanned {
72 node: hir::DeclItem(lower_item(it)),
78 pub fn lower_ty_binding(b: &TypeBinding) -> P<hir::TypeBinding> {
79 P(hir::TypeBinding { id: b.id, ident: b.ident, ty: lower_ty(&b.ty), span: b.span })
82 pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
86 TyInfer => hir::TyInfer,
87 TyVec(ref ty) => hir::TyVec(lower_ty(ty)),
88 TyPtr(ref mt) => hir::TyPtr(lower_mt(mt)),
89 TyRptr(ref region, ref mt) => {
90 hir::TyRptr(lower_opt_lifetime(region), lower_mt(mt))
93 hir::TyBareFn(P(hir::BareFnTy {
94 lifetimes: lower_lifetime_defs(&f.lifetimes),
95 unsafety: lower_unsafety(f.unsafety),
97 decl: lower_fn_decl(&f.decl)
100 TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(ty)).collect()),
101 TyParen(ref ty) => hir::TyParen(lower_ty(ty)),
102 TyPath(ref qself, ref path) => {
103 let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
109 hir::TyPath(qself, lower_path(path))
111 TyObjectSum(ref ty, ref bounds) => {
112 hir::TyObjectSum(lower_ty(ty),
113 lower_bounds(bounds))
115 TyFixedLengthVec(ref ty, ref e) => {
116 hir::TyFixedLengthVec(lower_ty(ty), lower_expr(e))
118 TyTypeof(ref expr) => {
119 hir::TyTypeof(lower_expr(expr))
121 TyPolyTraitRef(ref bounds) => {
122 hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(b)).collect())
124 TyMac(_) => panic!("TyMac should have been expanded by now."),
130 pub fn lower_foreign_mod(fm: &ForeignMod) -> hir::ForeignMod {
133 items: fm.items.iter().map(|x| lower_foreign_item(x)).collect(),
137 pub fn lower_variant(v: &Variant) -> P<hir::Variant> {
139 node: hir::Variant_ {
142 attrs: v.node.attrs.clone(),
143 kind: match v.node.kind {
144 TupleVariantKind(ref variant_args) => {
145 hir::TupleVariantKind(variant_args.iter().map(|ref x|
146 lower_variant_arg(x)).collect())
148 StructVariantKind(ref struct_def) => {
149 hir::StructVariantKind(lower_struct_def(struct_def))
152 disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(e)),
158 pub fn lower_path(p: &Path) -> hir::Path {
161 segments: p.segments.iter().map(|&PathSegment {identifier, ref parameters}|
163 identifier: identifier,
164 parameters: lower_path_parameters(parameters),
170 pub fn lower_path_parameters(path_parameters: &PathParameters) -> hir::PathParameters {
171 match *path_parameters {
172 AngleBracketedParameters(ref data) =>
173 hir::AngleBracketedParameters(lower_angle_bracketed_parameter_data(data)),
174 ParenthesizedParameters(ref data) =>
175 hir::ParenthesizedParameters(lower_parenthesized_parameter_data(data)),
179 pub fn lower_angle_bracketed_parameter_data(data: &AngleBracketedParameterData)
180 -> hir::AngleBracketedParameterData {
181 let &AngleBracketedParameterData { ref lifetimes, ref types, ref bindings } = data;
182 hir::AngleBracketedParameterData {
183 lifetimes: lower_lifetimes(lifetimes),
184 types: types.iter().map(|ty| lower_ty(ty)).collect(),
185 bindings: bindings.iter().map(|b| lower_ty_binding(b)).collect(),
189 pub fn lower_parenthesized_parameter_data(data: &ParenthesizedParameterData)
190 -> hir::ParenthesizedParameterData {
191 let &ParenthesizedParameterData { ref inputs, ref output, span } = data;
192 hir::ParenthesizedParameterData {
193 inputs: inputs.iter().map(|ty| lower_ty(ty)).collect(),
194 output: output.as_ref().map(|ty| lower_ty(ty)),
199 pub fn lower_local(l: &Local) -> P<hir::Local> {
202 ty: l.ty.as_ref().map(|t| lower_ty(t)),
203 pat: lower_pat(&l.pat),
204 init: l.init.as_ref().map(|e| lower_expr(e)),
209 pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ {
211 SelfStatic => hir::SelfStatic,
212 SelfValue(v) => hir::SelfValue(v),
213 SelfRegion(ref lifetime, m, ident) => {
214 hir::SelfRegion(lower_opt_lifetime(lifetime), lower_mutability(m), ident)
216 SelfExplicit(ref typ, ident) => {
217 hir::SelfExplicit(lower_ty(typ), ident)
222 pub fn lower_mutability(m: Mutability) -> hir::Mutability {
224 MutMutable => hir::MutMutable,
225 MutImmutable => hir::MutImmutable,
229 pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf {
230 Spanned { node: lower_explicit_self_underscore(&s.node), span: s.span }
233 pub fn lower_arg(arg: &Arg) -> hir::Arg {
234 hir::Arg { id: arg.id, pat: lower_pat(&arg.pat), ty: lower_ty(&arg.ty) }
237 pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
239 inputs: decl.inputs.iter().map(|x| lower_arg(x)).collect(),
240 output: match decl.output {
241 Return(ref ty) => hir::Return(lower_ty(ty)),
242 DefaultReturn(span) => hir::DefaultReturn(span),
243 NoReturn(span) => hir::NoReturn(span)
245 variadic: decl.variadic,
249 pub fn lower_ty_param_bound(tpb: &TyParamBound) -> hir::TyParamBound {
251 TraitTyParamBound(ref ty, modifier) => {
252 hir::TraitTyParamBound(lower_poly_trait_ref(ty), lower_trait_bound_modifier(modifier))
254 RegionTyParamBound(ref lifetime) => hir::RegionTyParamBound(lower_lifetime(lifetime)),
258 pub fn lower_ty_param(tp: &TyParam) -> hir::TyParam {
262 bounds: lower_bounds(&tp.bounds),
263 default: tp.default.as_ref().map(|x| lower_ty(x)),
268 pub fn lower_ty_params(tps: &OwnedSlice<TyParam>) -> OwnedSlice<hir::TyParam> {
269 tps.iter().map(|tp| lower_ty_param(tp)).collect()
272 pub fn lower_lifetime(l: &Lifetime) -> hir::Lifetime {
273 hir::Lifetime { id: l.id, name: l.name, span: l.span }
276 pub fn lower_lifetime_def(l: &LifetimeDef) -> hir::LifetimeDef {
277 hir::LifetimeDef { lifetime: lower_lifetime(&l.lifetime), bounds: lower_lifetimes(&l.bounds) }
280 pub fn lower_lifetimes(lts: &Vec<Lifetime>) -> Vec<hir::Lifetime> {
281 lts.iter().map(|l| lower_lifetime(l)).collect()
284 pub fn lower_lifetime_defs(lts: &Vec<LifetimeDef>) -> Vec<hir::LifetimeDef> {
285 lts.iter().map(|l| lower_lifetime_def(l)).collect()
288 pub fn lower_opt_lifetime(o_lt: &Option<Lifetime>) -> Option<hir::Lifetime> {
289 o_lt.as_ref().map(|lt| lower_lifetime(lt))
292 pub fn lower_generics(g: &Generics) -> hir::Generics {
294 ty_params: lower_ty_params(&g.ty_params),
295 lifetimes: lower_lifetime_defs(&g.lifetimes),
296 where_clause: lower_where_clause(&g.where_clause),
300 pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause {
303 predicates: wc.predicates.iter().map(|predicate|
304 lower_where_predicate(predicate)).collect(),
308 pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate {
310 WherePredicate::BoundPredicate(WhereBoundPredicate{ ref bound_lifetimes,
314 hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
315 bound_lifetimes: lower_lifetime_defs(bound_lifetimes),
316 bounded_ty: lower_ty(bounded_ty),
317 bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(),
321 WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
324 hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
326 lifetime: lower_lifetime(lifetime),
327 bounds: bounds.iter().map(|bound| lower_lifetime(bound)).collect()
330 WherePredicate::EqPredicate(WhereEqPredicate{ id,
334 hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{
336 path: lower_path(path),
344 pub fn lower_struct_def(sd: &StructDef) -> P<hir::StructDef> {
346 fields: sd.fields.iter().map(|f| lower_struct_field(f)).collect(),
351 pub fn lower_trait_ref(p: &TraitRef) -> hir::TraitRef {
352 hir::TraitRef { path: lower_path(&p.path), ref_id: p.ref_id }
355 pub fn lower_poly_trait_ref(p: &PolyTraitRef) -> hir::PolyTraitRef {
357 bound_lifetimes: lower_lifetime_defs(&p.bound_lifetimes),
358 trait_ref: lower_trait_ref(&p.trait_ref),
363 pub fn lower_struct_field(f: &StructField) -> hir::StructField {
365 node: hir::StructField_ {
367 kind: lower_struct_field_kind(&f.node.kind),
368 ty: lower_ty(&f.node.ty),
369 attrs: f.node.attrs.clone(),
375 pub fn lower_field(f: &Field) -> hir::Field {
377 name: respan(f.ident.span, f.ident.node.name),
378 expr: lower_expr(&f.expr), span: f.span
382 pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
383 hir::MutTy { ty: lower_ty(&mt.ty), mutbl: lower_mutability(mt.mutbl) }
386 pub fn lower_opt_bounds(b: &Option<OwnedSlice<TyParamBound>>)
387 -> Option<OwnedSlice<hir::TyParamBound>> {
388 b.as_ref().map(|ref bounds| lower_bounds(bounds))
391 fn lower_bounds(bounds: &TyParamBounds) -> hir::TyParamBounds {
392 bounds.iter().map(|bound| lower_ty_param_bound(bound)).collect()
395 fn lower_variant_arg(va: &VariantArg) -> hir::VariantArg {
396 hir::VariantArg { id: va.id, ty: lower_ty(&va.ty) }
399 pub fn lower_block(b: &Block) -> P<hir::Block> {
402 stmts: b.stmts.iter().map(|s| lower_stmt(s)).collect(),
403 expr: b.expr.as_ref().map(|ref x| lower_expr(x)),
404 rules: lower_block_check_mode(&b.rules),
409 pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
411 ItemExternCrate(string) => hir::ItemExternCrate(string),
412 ItemUse(ref view_path) => {
413 hir::ItemUse(lower_view_path(view_path))
415 ItemStatic(ref t, m, ref e) => {
416 hir::ItemStatic(lower_ty(t), lower_mutability(m), lower_expr(e))
418 ItemConst(ref t, ref e) => {
419 hir::ItemConst(lower_ty(t), lower_expr(e))
421 ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
424 lower_unsafety(unsafety),
425 lower_constness(constness),
427 lower_generics(generics),
431 ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
432 ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)),
433 ItemTy(ref t, ref generics) => {
434 hir::ItemTy(lower_ty(t), lower_generics(generics))
436 ItemEnum(ref enum_definition, ref generics) => {
439 variants: enum_definition.variants.iter().map(|x| lower_variant(x)).collect(),
441 lower_generics(generics))
443 ItemStruct(ref struct_def, ref generics) => {
444 let struct_def = lower_struct_def(struct_def);
445 hir::ItemStruct(struct_def, lower_generics(generics))
447 ItemDefaultImpl(unsafety, ref trait_ref) => {
448 hir::ItemDefaultImpl(lower_unsafety(unsafety), lower_trait_ref(trait_ref))
450 ItemImpl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => {
451 let new_impl_items = impl_items.iter().map(|item| lower_impl_item(item)).collect();
452 let ifce = ifce.as_ref().map(|trait_ref| lower_trait_ref(trait_ref));
453 hir::ItemImpl(lower_unsafety(unsafety),
454 lower_impl_polarity(polarity),
455 lower_generics(generics),
460 ItemTrait(unsafety, ref generics, ref bounds, ref items) => {
461 let bounds = lower_bounds(bounds);
462 let items = items.iter().map(|item| lower_trait_item(item)).collect();
463 hir::ItemTrait(lower_unsafety(unsafety),
464 lower_generics(generics),
468 ItemMac(_) => panic!("Shouldn't still be around"),
472 pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
476 attrs: i.attrs.clone(),
478 ConstTraitItem(ref ty, ref default) => {
479 hir::ConstTraitItem(lower_ty(ty),
480 default.as_ref().map(|x| lower_expr(x)))
482 MethodTraitItem(ref sig, ref body) => {
483 hir::MethodTraitItem(lower_method_sig(sig),
484 body.as_ref().map(|x| lower_block(x)))
486 TypeTraitItem(ref bounds, ref default) => {
487 hir::TypeTraitItem(lower_bounds(bounds),
488 default.as_ref().map(|x| lower_ty(x)))
495 pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
499 attrs: i.attrs.clone(),
500 vis: lower_visibility(i.vis),
502 ConstImplItem(ref ty, ref expr) => {
503 hir::ConstImplItem(lower_ty(ty), lower_expr(expr))
505 MethodImplItem(ref sig, ref body) => {
506 hir::MethodImplItem(lower_method_sig(sig),
509 TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)),
510 MacImplItem(..) => panic!("Shouldn't exist any more"),
516 pub fn lower_mod(m: &Mod) -> hir::Mod {
517 hir::Mod { inner: m.inner, items: m.items.iter().map(|x| lower_item(x)).collect() }
520 pub fn lower_crate(c: &Crate) -> hir::Crate {
522 module: lower_mod(&c.module),
523 attrs: c.attrs.clone(),
524 config: c.config.clone(),
526 exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(m)).collect(),
530 pub fn lower_macro_def(m: &MacroDef) -> hir::MacroDef {
533 attrs: m.attrs.clone(),
536 imported_from: m.imported_from.map(|x| x.name),
538 use_locally: m.use_locally,
539 allow_internal_unstable: m.allow_internal_unstable,
540 body: m.body.clone(),
544 // fold one item into possibly many items
545 pub fn lower_item(i: &Item) -> P<hir::Item> {
546 P(lower_item_simple(i))
549 // fold one item into exactly one item
550 pub fn lower_item_simple(i: &Item) -> hir::Item {
551 let node = lower_item_underscore(&i.node);
556 attrs: i.attrs.clone(),
558 vis: lower_visibility(i.vis),
563 pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
567 attrs: i.attrs.clone(),
569 ForeignItemFn(ref fdec, ref generics) => {
570 hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics))
572 ForeignItemStatic(ref t, m) => {
573 hir::ForeignItemStatic(lower_ty(t), m)
576 vis: lower_visibility(i.vis),
581 pub fn lower_method_sig(sig: &MethodSig) -> hir::MethodSig {
583 generics: lower_generics(&sig.generics),
585 explicit_self: lower_explicit_self(&sig.explicit_self),
586 unsafety: lower_unsafety(sig.unsafety),
587 constness: lower_constness(sig.constness),
588 decl: lower_fn_decl(&sig.decl),
592 pub fn lower_unsafety(u: Unsafety) -> hir::Unsafety {
594 Unsafety::Unsafe => hir::Unsafety::Unsafe,
595 Unsafety::Normal => hir::Unsafety::Normal,
599 pub fn lower_constness(c: Constness) -> hir::Constness {
601 Constness::Const => hir::Constness::Const,
602 Constness::NotConst => hir::Constness::NotConst,
606 pub fn lower_unop(u: UnOp) -> hir::UnOp {
608 UnUniq => hir::UnUniq,
609 UnDeref => hir::UnDeref,
615 pub fn lower_binop(b: BinOp) -> hir::BinOp {
625 BiBitXor => hir::BiBitXor,
626 BiBitAnd => hir::BiBitAnd,
627 BiBitOr => hir::BiBitOr,
641 pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
645 PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)),
646 PatIdent(ref binding_mode, pth1, ref sub) => {
647 hir::PatIdent(lower_binding_mode(binding_mode),
649 sub.as_ref().map(|x| lower_pat(x)))
651 PatLit(ref e) => hir::PatLit(lower_expr(e)),
652 PatEnum(ref pth, ref pats) => {
653 hir::PatEnum(lower_path(pth),
654 pats.as_ref().map(|pats| pats.iter().map(|x| lower_pat(x)).collect()))
656 PatQPath(ref qself, ref pth) => {
657 let qself = hir::QSelf {
658 ty: lower_ty(&qself.ty),
659 position: qself.position,
661 hir::PatQPath(qself, lower_path(pth))
663 PatStruct(ref pth, ref fields, etc) => {
664 let pth = lower_path(pth);
665 let fs = fields.iter().map(|f| {
666 Spanned { span: f.span,
667 node: hir::FieldPat {
669 pat: lower_pat(&f.node.pat),
670 is_shorthand: f.node.is_shorthand,
673 hir::PatStruct(pth, fs, etc)
675 PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()),
676 PatBox(ref inner) => hir::PatBox(lower_pat(inner)),
677 PatRegion(ref inner, mutbl) => hir::PatRegion(lower_pat(inner),
678 lower_mutability(mutbl)),
679 PatRange(ref e1, ref e2) => {
680 hir::PatRange(lower_expr(e1), lower_expr(e2))
682 PatVec(ref before, ref slice, ref after) => {
683 hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(),
684 slice.as_ref().map(|x| lower_pat(x)),
685 after.iter().map(|x| lower_pat(x)).collect())
687 PatMac(_) => panic!("Shouldn't exist here"),
693 pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
697 ExprBox(ref p, ref e) => {
698 hir::ExprBox(p.as_ref().map(|e| lower_expr(e)), lower_expr(e))
700 ExprVec(ref exprs) => {
701 hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
703 ExprRepeat(ref expr, ref count) => {
704 hir::ExprRepeat(lower_expr(expr), lower_expr(count))
706 ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
707 ExprCall(ref f, ref args) => {
708 hir::ExprCall(lower_expr(f),
709 args.iter().map(|x| lower_expr(x)).collect())
711 ExprMethodCall(i, ref tps, ref args) => {
713 respan(i.span, i.node.name),
714 tps.iter().map(|x| lower_ty(x)).collect(),
715 args.iter().map(|x| lower_expr(x)).collect())
717 ExprBinary(binop, ref lhs, ref rhs) => {
718 hir::ExprBinary(lower_binop(binop),
722 ExprUnary(op, ref ohs) => {
723 hir::ExprUnary(lower_unop(op), lower_expr(ohs))
725 ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
726 ExprCast(ref expr, ref ty) => {
727 hir::ExprCast(lower_expr(expr), lower_ty(ty))
729 ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
730 ExprIf(ref cond, ref tr, ref fl) => {
731 hir::ExprIf(lower_expr(cond),
733 fl.as_ref().map(|x| lower_expr(x)))
735 ExprWhile(ref cond, ref body, opt_ident) => {
736 hir::ExprWhile(lower_expr(cond),
740 ExprLoop(ref body, opt_ident) => {
741 hir::ExprLoop(lower_block(body),
744 ExprMatch(ref expr, ref arms, ref source) => {
745 hir::ExprMatch(lower_expr(expr),
746 arms.iter().map(|x| lower_arm(x)).collect(),
747 lower_match_source(source))
749 ExprClosure(capture_clause, ref decl, ref body) => {
750 hir::ExprClosure(lower_capture_clause(capture_clause),
754 ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
755 ExprAssign(ref el, ref er) => {
756 hir::ExprAssign(lower_expr(el), lower_expr(er))
758 ExprAssignOp(op, ref el, ref er) => {
759 hir::ExprAssignOp(lower_binop(op),
763 ExprField(ref el, ident) => {
764 hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
766 ExprTupField(ref el, ident) => {
767 hir::ExprTupField(lower_expr(el), ident)
769 ExprIndex(ref el, ref er) => {
770 hir::ExprIndex(lower_expr(el), lower_expr(er))
772 ExprRange(ref e1, ref e2) => {
773 hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
774 e2.as_ref().map(|x| lower_expr(x)))
776 ExprPath(ref qself, ref path) => {
777 let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
783 hir::ExprPath(qself, lower_path(path))
785 ExprBreak(opt_ident) => hir::ExprBreak(opt_ident),
786 ExprAgain(opt_ident) => hir::ExprAgain(opt_ident),
787 ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(x))),
788 ExprInlineAsm(InlineAsm {
798 }) => hir::ExprInlineAsm(hir::InlineAsm {
799 inputs: inputs.iter().map(|&(ref c, ref input)| {
800 (c.clone(), lower_expr(input))
802 outputs: outputs.iter().map(|&(ref c, ref out, ref is_rw)| {
803 (c.clone(), lower_expr(out), *is_rw)
806 asm_str_style: asm_str_style,
807 clobbers: clobbers.clone(),
809 alignstack: alignstack,
813 ExprStruct(ref path, ref fields, ref maybe_expr) => {
814 hir::ExprStruct(lower_path(path),
815 fields.iter().map(|x| lower_field(x)).collect(),
816 maybe_expr.as_ref().map(|x| lower_expr(x)))
818 ExprParen(ref ex) => {
819 return lower_expr(ex);
824 ExprMac(_) => panic!("Shouldn't exist here"),
830 pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
832 StmtDecl(ref d, id) => {
834 node: hir::StmtDecl(lower_decl(d), id),
838 StmtExpr(ref e, id) => {
840 node: hir::StmtExpr(lower_expr(e), id),
844 StmtSemi(ref e, id) => {
846 node: hir::StmtSemi(lower_expr(e), id),
850 StmtMac(..) => panic!("Shouldn't exist here")
854 pub fn lower_match_source(m: &MatchSource) -> hir::MatchSource {
856 MatchSource::Normal => hir::MatchSource::Normal,
857 MatchSource::IfLetDesugar { contains_else_clause } => {
858 hir::MatchSource::IfLetDesugar { contains_else_clause: contains_else_clause }
860 MatchSource::WhileLetDesugar => hir::MatchSource::WhileLetDesugar,
861 MatchSource::ForLoopDesugar => hir::MatchSource::ForLoopDesugar,
865 pub fn lower_capture_clause(c: CaptureClause) -> hir::CaptureClause {
867 CaptureByValue => hir::CaptureByValue,
868 CaptureByRef => hir::CaptureByRef,
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,