pub fn lower_decl(lctx: &LoweringContext, d: &Decl) -> P<hir::Decl> {
match d.node {
- DeclLocal(ref l) => P(Spanned {
+ DeclKind::Local(ref l) => P(Spanned {
node: hir::DeclLocal(lower_local(lctx, l)),
span: d.span,
}),
- DeclItem(ref it) => P(Spanned {
+ DeclKind::Item(ref it) => P(Spanned {
node: hir::DeclItem(lower_item_id(lctx, it)),
span: d.span,
}),
}
pub fn lower_ty(lctx: &LoweringContext, t: &Ty) -> P<hir::Ty> {
+ use syntax::ast::TyKind::*;
P(hir::Ty {
id: t.id,
node: match t.node {
- TyInfer => hir::TyInfer,
- TyVec(ref ty) => hir::TyVec(lower_ty(lctx, ty)),
- TyPtr(ref mt) => hir::TyPtr(lower_mt(lctx, mt)),
- TyRptr(ref region, ref mt) => {
+ Infer => hir::TyInfer,
+ Vec(ref ty) => hir::TyVec(lower_ty(lctx, ty)),
+ Ptr(ref mt) => hir::TyPtr(lower_mt(lctx, mt)),
+ Rptr(ref region, ref mt) => {
hir::TyRptr(lower_opt_lifetime(lctx, region), lower_mt(lctx, mt))
}
- TyBareFn(ref f) => {
+ BareFn(ref f) => {
hir::TyBareFn(P(hir::BareFnTy {
lifetimes: lower_lifetime_defs(lctx, &f.lifetimes),
unsafety: lower_unsafety(lctx, f.unsafety),
decl: lower_fn_decl(lctx, &f.decl),
}))
}
- TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(lctx, ty)).collect()),
- TyParen(ref ty) => {
+ Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(lctx, ty)).collect()),
+ Paren(ref ty) => {
return lower_ty(lctx, ty);
}
- TyPath(ref qself, ref path) => {
+ Path(ref qself, ref path) => {
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: lower_ty(lctx, ty),
});
hir::TyPath(qself, lower_path(lctx, path))
}
- TyObjectSum(ref ty, ref bounds) => {
+ ObjectSum(ref ty, ref bounds) => {
hir::TyObjectSum(lower_ty(lctx, ty), lower_bounds(lctx, bounds))
}
- TyFixedLengthVec(ref ty, ref e) => {
+ FixedLengthVec(ref ty, ref e) => {
hir::TyFixedLengthVec(lower_ty(lctx, ty), lower_expr(lctx, e))
}
- TyTypeof(ref expr) => {
+ Typeof(ref expr) => {
hir::TyTypeof(lower_expr(lctx, expr))
}
- TyPolyTraitRef(ref bounds) => {
+ PolyTraitRef(ref bounds) => {
hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(lctx, b)).collect())
}
- TyMac(_) => panic!("TyMac should have been expanded by now."),
+ Mac(_) => panic!("TyMac should have been expanded by now."),
},
span: t.span,
})
}
pub fn lower_explicit_self_underscore(lctx: &LoweringContext,
- es: &ExplicitSelf_)
+ es: &SelfKind)
-> hir::ExplicitSelf_ {
match *es {
- SelfStatic => hir::SelfStatic,
- SelfValue(v) => hir::SelfValue(v.name),
- SelfRegion(ref lifetime, m, ident) => {
+ SelfKind::Static => hir::SelfStatic,
+ SelfKind::Value(v) => hir::SelfValue(v.name),
+ SelfKind::Region(ref lifetime, m, ident) => {
hir::SelfRegion(lower_opt_lifetime(lctx, lifetime),
lower_mutability(lctx, m),
ident.name)
}
- SelfExplicit(ref typ, ident) => {
+ SelfKind::Explicit(ref typ, ident) => {
hir::SelfExplicit(lower_ty(lctx, typ), ident.name)
}
}
})
}
-pub fn lower_item_underscore(lctx: &LoweringContext, i: &Item_) -> hir::Item_ {
+pub fn lower_item_kind(lctx: &LoweringContext, i: &ItemKind) -> hir::Item_ {
match *i {
- ItemExternCrate(string) => hir::ItemExternCrate(string),
- ItemUse(ref view_path) => {
+ ItemKind::ExternCrate(string) => hir::ItemExternCrate(string),
+ ItemKind::Use(ref view_path) => {
hir::ItemUse(lower_view_path(lctx, view_path))
}
- ItemStatic(ref t, m, ref e) => {
+ ItemKind::Static(ref t, m, ref e) => {
hir::ItemStatic(lower_ty(lctx, t),
lower_mutability(lctx, m),
lower_expr(lctx, e))
}
- ItemConst(ref t, ref e) => {
+ ItemKind::Const(ref t, ref e) => {
hir::ItemConst(lower_ty(lctx, t), lower_expr(lctx, e))
}
- ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
+ ItemKind::Fn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
hir::ItemFn(lower_fn_decl(lctx, decl),
lower_unsafety(lctx, unsafety),
lower_constness(lctx, constness),
lower_generics(lctx, generics),
lower_block(lctx, body))
}
- ItemMod(ref m) => hir::ItemMod(lower_mod(lctx, m)),
- ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(lctx, nm)),
- ItemTy(ref t, ref generics) => {
+ ItemKind::Mod(ref m) => hir::ItemMod(lower_mod(lctx, m)),
+ ItemKind::ForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(lctx, nm)),
+ ItemKind::Ty(ref t, ref generics) => {
hir::ItemTy(lower_ty(lctx, t), lower_generics(lctx, generics))
}
- ItemEnum(ref enum_definition, ref generics) => {
+ ItemKind::Enum(ref enum_definition, ref generics) => {
hir::ItemEnum(hir::EnumDef {
variants: enum_definition.variants
.iter()
},
lower_generics(lctx, generics))
}
- ItemStruct(ref struct_def, ref generics) => {
+ ItemKind::Struct(ref struct_def, ref generics) => {
let struct_def = lower_variant_data(lctx, struct_def);
hir::ItemStruct(struct_def, lower_generics(lctx, generics))
}
- ItemDefaultImpl(unsafety, ref trait_ref) => {
+ ItemKind::DefaultImpl(unsafety, ref trait_ref) => {
hir::ItemDefaultImpl(lower_unsafety(lctx, unsafety),
lower_trait_ref(lctx, trait_ref))
}
- ItemImpl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => {
+ ItemKind::Impl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => {
let new_impl_items = impl_items.iter()
.map(|item| lower_impl_item(lctx, item))
.collect();
lower_ty(lctx, ty),
new_impl_items)
}
- ItemTrait(unsafety, ref generics, ref bounds, ref items) => {
+ ItemKind::Trait(unsafety, ref generics, ref bounds, ref items) => {
let bounds = lower_bounds(lctx, bounds);
let items = items.iter().map(|item| lower_trait_item(lctx, item)).collect();
hir::ItemTrait(lower_unsafety(lctx, unsafety),
bounds,
items)
}
- ItemMac(_) => panic!("Shouldn't still be around"),
+ ItemKind::Mac(_) => panic!("Shouldn't still be around"),
}
}
}
pub fn lower_item(lctx: &LoweringContext, i: &Item) -> hir::Item {
- let node = lower_item_underscore(lctx, &i.node);
+ let node = lower_item_kind(lctx, &i.node);
hir::Item {
id: i.id,
name: i.ident.name,
attrs: lower_attrs(lctx, &i.attrs),
node: match i.node {
- ForeignItemFn(ref fdec, ref generics) => {
+ ForeignItemKind::Fn(ref fdec, ref generics) => {
hir::ForeignItemFn(lower_fn_decl(lctx, fdec), lower_generics(lctx, generics))
}
- ForeignItemStatic(ref t, m) => {
+ ForeignItemKind::Static(ref t, m) => {
hir::ForeignItemStatic(lower_ty(lctx, t), m)
}
},
// }
//
// But for now there are type-inference issues doing that.
- ExprBox(ref e) => {
+ ExprKind::Box(ref e) => {
hir::ExprBox(lower_expr(lctx, e))
}
// Desugar ExprBox: `in (PLACE) EXPR`
- ExprInPlace(ref placer, ref value_expr) => {
+ ExprKind::InPlace(ref placer, ref value_expr) => {
// to:
//
// let p = PLACE;
});
}
- ExprVec(ref exprs) => {
+ ExprKind::Vec(ref exprs) => {
hir::ExprVec(exprs.iter().map(|x| lower_expr(lctx, x)).collect())
}
- ExprRepeat(ref expr, ref count) => {
+ ExprKind::Repeat(ref expr, ref count) => {
let expr = lower_expr(lctx, expr);
let count = lower_expr(lctx, count);
hir::ExprRepeat(expr, count)
}
- ExprTup(ref elts) => {
+ ExprKind::Tup(ref elts) => {
hir::ExprTup(elts.iter().map(|x| lower_expr(lctx, x)).collect())
}
- ExprCall(ref f, ref args) => {
+ ExprKind::Call(ref f, ref args) => {
let f = lower_expr(lctx, f);
hir::ExprCall(f, args.iter().map(|x| lower_expr(lctx, x)).collect())
}
- ExprMethodCall(i, ref tps, ref args) => {
+ ExprKind::MethodCall(i, ref tps, ref args) => {
let tps = tps.iter().map(|x| lower_ty(lctx, x)).collect();
let args = args.iter().map(|x| lower_expr(lctx, x)).collect();
hir::ExprMethodCall(respan(i.span, i.node.name), tps, args)
}
- ExprBinary(binop, ref lhs, ref rhs) => {
+ ExprKind::Binary(binop, ref lhs, ref rhs) => {
let binop = lower_binop(lctx, binop);
let lhs = lower_expr(lctx, lhs);
let rhs = lower_expr(lctx, rhs);
hir::ExprBinary(binop, lhs, rhs)
}
- ExprUnary(op, ref ohs) => {
+ ExprKind::Unary(op, ref ohs) => {
let op = lower_unop(lctx, op);
let ohs = lower_expr(lctx, ohs);
hir::ExprUnary(op, ohs)
}
- ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
- ExprCast(ref expr, ref ty) => {
+ ExprKind::Lit(ref l) => hir::ExprLit(P((**l).clone())),
+ ExprKind::Cast(ref expr, ref ty) => {
let expr = lower_expr(lctx, expr);
hir::ExprCast(expr, lower_ty(lctx, ty))
}
- ExprType(ref expr, ref ty) => {
+ ExprKind::Type(ref expr, ref ty) => {
let expr = lower_expr(lctx, expr);
hir::ExprType(expr, lower_ty(lctx, ty))
}
- ExprAddrOf(m, ref ohs) => {
+ ExprKind::AddrOf(m, ref ohs) => {
let m = lower_mutability(lctx, m);
let ohs = lower_expr(lctx, ohs);
hir::ExprAddrOf(m, ohs)
}
// More complicated than you might expect because the else branch
// might be `if let`.
- ExprIf(ref cond, ref blk, ref else_opt) => {
+ ExprKind::If(ref cond, ref blk, ref else_opt) => {
let else_opt = else_opt.as_ref().map(|els| {
match els.node {
- ExprIfLet(..) => {
+ ExprKind::IfLet(..) => {
cache_ids(lctx, e.id, |lctx| {
// wrap the if-let expr in a block
let span = els.span;
hir::ExprIf(lower_expr(lctx, cond), lower_block(lctx, blk), else_opt)
}
- ExprWhile(ref cond, ref body, opt_ident) => {
+ ExprKind::While(ref cond, ref body, opt_ident) => {
hir::ExprWhile(lower_expr(lctx, cond), lower_block(lctx, body),
opt_ident.map(|ident| lower_ident(lctx, ident)))
}
- ExprLoop(ref body, opt_ident) => {
+ ExprKind::Loop(ref body, opt_ident) => {
hir::ExprLoop(lower_block(lctx, body),
opt_ident.map(|ident| lower_ident(lctx, ident)))
}
- ExprMatch(ref expr, ref arms) => {
+ ExprKind::Match(ref expr, ref arms) => {
hir::ExprMatch(lower_expr(lctx, expr),
arms.iter().map(|x| lower_arm(lctx, x)).collect(),
hir::MatchSource::Normal)
}
- ExprClosure(capture_clause, ref decl, ref body) => {
+ ExprKind::Closure(capture_clause, ref decl, ref body) => {
hir::ExprClosure(lower_capture_clause(lctx, capture_clause),
lower_fn_decl(lctx, decl),
lower_block(lctx, body))
}
- ExprBlock(ref blk) => hir::ExprBlock(lower_block(lctx, blk)),
- ExprAssign(ref el, ref er) => {
+ ExprKind::Block(ref blk) => hir::ExprBlock(lower_block(lctx, blk)),
+ ExprKind::Assign(ref el, ref er) => {
hir::ExprAssign(lower_expr(lctx, el), lower_expr(lctx, er))
}
- ExprAssignOp(op, ref el, ref er) => {
+ ExprKind::AssignOp(op, ref el, ref er) => {
hir::ExprAssignOp(lower_binop(lctx, op),
lower_expr(lctx, el),
lower_expr(lctx, er))
}
- ExprField(ref el, ident) => {
+ ExprKind::Field(ref el, ident) => {
hir::ExprField(lower_expr(lctx, el), respan(ident.span, ident.node.name))
}
- ExprTupField(ref el, ident) => {
+ ExprKind::TupField(ref el, ident) => {
hir::ExprTupField(lower_expr(lctx, el), ident)
}
- ExprIndex(ref el, ref er) => {
+ ExprKind::Index(ref el, ref er) => {
hir::ExprIndex(lower_expr(lctx, el), lower_expr(lctx, er))
}
- ExprRange(ref e1, ref e2) => {
+ ExprKind::Range(ref e1, ref e2) => {
hir::ExprRange(e1.as_ref().map(|x| lower_expr(lctx, x)),
e2.as_ref().map(|x| lower_expr(lctx, x)))
}
- ExprPath(ref qself, ref path) => {
+ ExprKind::Path(ref qself, ref path) => {
let hir_qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: lower_ty(lctx, ty),
});
hir::ExprPath(hir_qself, lower_path_full(lctx, path, qself.is_none()))
}
- ExprBreak(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| {
+ ExprKind::Break(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| {
respan(sp_ident.span, lower_ident(lctx, sp_ident.node))
})),
- ExprAgain(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| {
+ ExprKind::Again(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| {
respan(sp_ident.span, lower_ident(lctx, sp_ident.node))
})),
- ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(lctx, x))),
- ExprInlineAsm(InlineAsm {
+ ExprKind::Ret(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(lctx, x))),
+ ExprKind::InlineAsm(InlineAsm {
ref inputs,
ref outputs,
ref asm,
dialect: dialect,
expn_id: expn_id,
}),
- ExprStruct(ref path, ref fields, ref maybe_expr) => {
+ ExprKind::Struct(ref path, ref fields, ref maybe_expr) => {
hir::ExprStruct(lower_path(lctx, path),
fields.iter().map(|x| lower_field(lctx, x)).collect(),
maybe_expr.as_ref().map(|x| lower_expr(lctx, x)))
}
- ExprParen(ref ex) => {
+ ExprKind::Paren(ref ex) => {
// merge attributes into the inner expression.
return lower_expr(lctx, ex).map(|mut ex| {
ex.attrs.update(|attrs| {
// Desugar ExprIfLet
// From: `if let <pat> = <sub_expr> <body> [<else_opt>]`
- ExprIfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {
+ ExprKind::IfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {
// to:
//
// match <sub_expr> {
// Desugar ExprWhileLet
// From: `[opt_ident]: while let <pat> = <sub_expr> <body>`
- ExprWhileLet(ref pat, ref sub_expr, ref body, opt_ident) => {
+ ExprKind::WhileLet(ref pat, ref sub_expr, ref body, opt_ident) => {
// to:
//
// [opt_ident]: loop {
// Desugar ExprForLoop
// From: `[opt_ident]: for <pat> in <head> <body>`
- ExprForLoop(ref pat, ref head, ref body, opt_ident) => {
+ ExprKind::ForLoop(ref pat, ref head, ref body, opt_ident) => {
// to:
//
// {
});
}
- ExprMac(_) => panic!("Shouldn't exist here"),
+ ExprKind::Mac(_) => panic!("Shouldn't exist here"),
},
span: e.span,
attrs: e.attrs.clone(),
pub fn lower_stmt(lctx: &LoweringContext, s: &Stmt) -> hir::Stmt {
match s.node {
- StmtDecl(ref d, id) => {
+ StmtKind::Decl(ref d, id) => {
Spanned {
node: hir::StmtDecl(lower_decl(lctx, d), id),
span: s.span,
}
}
- StmtExpr(ref e, id) => {
+ StmtKind::Expr(ref e, id) => {
Spanned {
node: hir::StmtExpr(lower_expr(lctx, e), id),
span: s.span,
}
}
- StmtSemi(ref e, id) => {
+ StmtKind::Semi(ref e, id) => {
Spanned {
node: hir::StmtSemi(lower_expr(lctx, e), id),
span: s.span,
}
}
- StmtMac(..) => panic!("Shouldn't exist here"),
+ StmtKind::Mac(..) => panic!("Shouldn't exist here"),
}
}
-pub fn lower_capture_clause(_lctx: &LoweringContext, c: CaptureClause) -> hir::CaptureClause {
+pub fn lower_capture_clause(_lctx: &LoweringContext, c: CaptureBy) -> hir::CaptureClause {
match c {
- CaptureByValue => hir::CaptureByValue,
- CaptureByRef => hir::CaptureByRef,
+ CaptureBy::Value => hir::CaptureByValue,
+ CaptureBy::Ref => hir::CaptureByRef,
}
}
pub fn lower_block_check_mode(lctx: &LoweringContext, b: &BlockCheckMode) -> hir::BlockCheckMode {
match *b {
- DefaultBlock => hir::DefaultBlock,
- UnsafeBlock(u) => hir::UnsafeBlock(lower_unsafe_source(lctx, u)),
+ BlockCheckMode::Default => hir::DefaultBlock,
+ BlockCheckMode::Unsafe(u) => hir::UnsafeBlock(lower_unsafe_source(lctx, u)),
}
}