From 56713a1684c22742a3a4d3d2b19fa09fa6832024 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 25 Sep 2015 16:03:28 +1200 Subject: [PATCH] Add a lowering context --- src/librustc_driver/driver.rs | 22 +- src/librustc_driver/lib.rs | 1 + src/librustc_driver/pretty.rs | 6 +- src/librustc_front/lowering.rs | 890 ++++++++++++++-------------- src/librustc_trans/save/dump_csv.rs | 9 +- src/librustc_trans/save/mod.rs | 22 +- 6 files changed, 487 insertions(+), 463 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 91843d23cab..a3055d6d67c 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -31,7 +31,7 @@ use rustc_trans::trans; use rustc_typeck as typeck; use rustc_privacy; use rustc_front::hir; -use rustc_front::lowering::lower_crate; +use rustc_front::lowering::{lower_crate, LoweringContext}; use super::Compilation; use serialize::json; @@ -112,9 +112,11 @@ pub fn compile_input(sess: Session, let expanded_crate = assign_node_ids(&sess, expanded_crate); // Lower ast -> hir. + let foo = &42; + let lcx = LoweringContext::new(foo); let mut hir_forest = time(sess.time_passes(), "lowering ast -> hir", - || hir_map::Forest::new(lower_crate(&expanded_crate))); + || hir_map::Forest::new(lower_crate(&lcx, &expanded_crate))); let arenas = ty::CtxtArenas::new(); let ast_map = make_map(&sess, &mut hir_forest); @@ -128,7 +130,8 @@ pub fn compile_input(sess: Session, &ast_map, &expanded_crate, &ast_map.krate(), - &id[..])); + &id[..], + &lcx)); time(sess.time_passes(), "attribute checking", || { front::check_attr::check_crate(&sess, &expanded_crate); @@ -152,7 +155,8 @@ pub fn compile_input(sess: Session, &expanded_crate, tcx.map.krate(), &analysis, - tcx); + tcx, + &lcx); (control.after_analysis.callback)(state); tcx.sess.abort_if_errors(); @@ -278,6 +282,7 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> { pub ast_map: Option<&'a hir_map::Map<'ast>>, pub analysis: Option<&'a ty::CrateAnalysis>, pub tcx: Option<&'a ty::ctxt<'tcx>>, + pub lcx: Option<&'a LoweringContext<'tcx>>, pub trans: Option<&'a trans::CrateTranslation>, } @@ -299,6 +304,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { ast_map: None, analysis: None, tcx: None, + lcx: None, trans: None, } } @@ -333,13 +339,15 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { ast_map: &'a hir_map::Map<'ast>, krate: &'a ast::Crate, hir_crate: &'a hir::Crate, - crate_name: &'a str) + crate_name: &'a str, + lcx: &'a LoweringContext<'tcx>) -> CompileState<'a, 'ast, 'tcx> { CompileState { crate_name: Some(crate_name), ast_map: Some(ast_map), krate: Some(krate), hir_crate: Some(hir_crate), + lcx: Some(lcx), .. CompileState::empty(input, session, out_dir) } } @@ -350,13 +358,15 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { krate: &'a ast::Crate, hir_crate: &'a hir::Crate, analysis: &'a ty::CrateAnalysis, - tcx: &'a ty::ctxt<'tcx>) + tcx: &'a ty::ctxt<'tcx>, + lcx: &'a LoweringContext<'tcx>) -> CompileState<'a, 'ast, 'tcx> { CompileState { analysis: Some(analysis), tcx: Some(tcx), krate: Some(krate), hir_crate: Some(hir_crate), + lcx: Some(lcx), .. CompileState::empty(input, session, out_dir) } } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index e4f033efb58..276b747feb2 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -396,6 +396,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { time(state.session.time_passes(), "save analysis", || save::process_crate(state.tcx.unwrap(), + state.lcx.unwrap(), state.krate.unwrap(), state.analysis.unwrap(), state.out_dir)); diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index f0fa1ff70c6..53b940c57a7 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -47,7 +47,7 @@ use std::str::FromStr; use rustc::front::map as hir_map; use rustc::front::map::{blocks, NodePrinter}; use rustc_front::hir; -use rustc_front::lowering::lower_crate; +use rustc_front::lowering::{lower_crate, LoweringContext}; use rustc_front::print::pprust as pprust_hir; #[derive(Copy, Clone, PartialEq, Debug)] @@ -670,9 +670,11 @@ pub fn pretty_print_input(sess: Session, // There is some twisted, god-forsaken tangle of lifetimes here which makes // the ordering of stuff super-finicky. let mut hir_forest; + let foo = &42; + let lcx = LoweringContext::new(foo); let arenas = ty::CtxtArenas::new(); let ast_map = if compute_ast_map { - hir_forest = hir_map::Forest::new(lower_crate(&krate)); + hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate)); let map = driver::make_map(&sess, &mut hir_forest); Some(map) } else { diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index d1026f1dfb2..c3544ff1aa0 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -17,115 +17,121 @@ use syntax::ptr::P; use syntax::codemap::{respan, Spanned}; use syntax::owned_slice::OwnedSlice; +pub struct LoweringContext<'hir> { + // TODO + foo: &'hir i32, +} -pub fn lower_view_path(view_path: &ViewPath) -> P { +impl<'hir> LoweringContext<'hir> { + pub fn new(foo: &'hir i32) -> LoweringContext<'hir> { + LoweringContext { + foo: foo, + } + } +} + +pub fn lower_view_path(_lctx: &LoweringContext, view_path: &ViewPath) -> P { P(Spanned { node: match view_path.node { ViewPathSimple(ident, ref path) => { - hir::ViewPathSimple(ident.name, lower_path(path)) + hir::ViewPathSimple(ident.name, lower_path(_lctx, path)) } ViewPathGlob(ref path) => { - hir::ViewPathGlob(lower_path(path)) + hir::ViewPathGlob(lower_path(_lctx, path)) } ViewPathList(ref path, ref path_list_idents) => { - hir::ViewPathList(lower_path(path), - path_list_idents.iter() - .map(|path_list_ident| { - Spanned { - node: match path_list_ident.node { - PathListIdent { id, name, rename } => - hir::PathListIdent { - id: id, - name: name.name, - rename: rename.map(|x| x.name), - }, - PathListMod { id, rename } => - hir::PathListMod { - id: id, - rename: rename.map(|x| x.name), - }, - }, - span: path_list_ident.span, - } - }) - .collect()) + hir::ViewPathList(lower_path(_lctx, path), + path_list_idents.iter().map(|path_list_ident| { + Spanned { + node: match path_list_ident.node { + PathListIdent { id, name, rename } => + hir::PathListIdent { + id: id, + name: name.name, + rename: rename.map(|x| x.name), + }, + PathListMod { id, rename } => + hir::PathListMod { + id: id, + rename: rename.map(|x| x.name) + } + }, + span: path_list_ident.span + } + }).collect()) } }, span: view_path.span, }) } -pub fn lower_arm(arm: &Arm) -> hir::Arm { +pub fn lower_arm(_lctx: &LoweringContext, arm: &Arm) -> hir::Arm { hir::Arm { attrs: arm.attrs.clone(), - pats: arm.pats.iter().map(|x| lower_pat(x)).collect(), - guard: arm.guard.as_ref().map(|ref x| lower_expr(x)), - body: lower_expr(&arm.body), + pats: arm.pats.iter().map(|x| lower_pat(_lctx, x)).collect(), + guard: arm.guard.as_ref().map(|ref x| lower_expr(_lctx, x)), + body: lower_expr(_lctx, &arm.body), } } -pub fn lower_decl(d: &Decl) -> P { +pub fn lower_decl(_lctx: &LoweringContext, d: &Decl) -> P { match d.node { DeclLocal(ref l) => P(Spanned { - node: hir::DeclLocal(lower_local(l)), - span: d.span, + node: hir::DeclLocal(lower_local(_lctx, l)), + span: d.span }), DeclItem(ref it) => P(Spanned { - node: hir::DeclItem(lower_item(it)), - span: d.span, + node: hir::DeclItem(lower_item(_lctx, it)), + span: d.span }), } } -pub fn lower_ty_binding(b: &TypeBinding) -> P { - P(hir::TypeBinding { - id: b.id, - name: b.ident.name, - ty: lower_ty(&b.ty), - span: b.span, - }) +pub fn lower_ty_binding(_lctx: &LoweringContext, b: &TypeBinding) -> P { + P(hir::TypeBinding { id: b.id, name: b.ident.name, ty: lower_ty(_lctx, &b.ty), span: b.span }) } -pub fn lower_ty(t: &Ty) -> P { +pub fn lower_ty(_lctx: &LoweringContext, t: &Ty) -> P { P(hir::Ty { id: t.id, node: match t.node { TyInfer => hir::TyInfer, - TyVec(ref ty) => hir::TyVec(lower_ty(ty)), - TyPtr(ref mt) => hir::TyPtr(lower_mt(mt)), + TyVec(ref ty) => hir::TyVec(lower_ty(_lctx, ty)), + TyPtr(ref mt) => hir::TyPtr(lower_mt(_lctx, mt)), TyRptr(ref region, ref mt) => { - hir::TyRptr(lower_opt_lifetime(region), lower_mt(mt)) + hir::TyRptr(lower_opt_lifetime(_lctx, region), lower_mt(_lctx, mt)) } TyBareFn(ref f) => { hir::TyBareFn(P(hir::BareFnTy { - lifetimes: lower_lifetime_defs(&f.lifetimes), - unsafety: lower_unsafety(f.unsafety), + lifetimes: lower_lifetime_defs(_lctx, &f.lifetimes), + unsafety: lower_unsafety(_lctx, f.unsafety), abi: f.abi, - decl: lower_fn_decl(&f.decl), + decl: lower_fn_decl(_lctx, &f.decl), })) } - TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(ty)).collect()), - TyParen(ref ty) => hir::TyParen(lower_ty(ty)), + TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(_lctx, ty)).collect()), + TyParen(ref ty) => hir::TyParen(lower_ty(_lctx, ty)), TyPath(ref qself, ref path) => { let qself = qself.as_ref().map(|&QSelf { ref ty, position }| { hir::QSelf { - ty: lower_ty(ty), + ty: lower_ty(_lctx, ty), position: position, } }); - hir::TyPath(qself, lower_path(path)) + hir::TyPath(qself, lower_path(_lctx, path)) } TyObjectSum(ref ty, ref bounds) => { - hir::TyObjectSum(lower_ty(ty), lower_bounds(bounds)) + hir::TyObjectSum(lower_ty(_lctx, ty), + lower_bounds(_lctx, bounds)) } TyFixedLengthVec(ref ty, ref e) => { - hir::TyFixedLengthVec(lower_ty(ty), lower_expr(e)) + hir::TyFixedLengthVec(lower_ty(_lctx, ty), lower_expr(_lctx, e)) } TyTypeof(ref expr) => { - hir::TyTypeof(lower_expr(expr)) + hir::TyTypeof(lower_expr(_lctx, expr)) } TyPolyTraitRef(ref bounds) => { - hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(b)).collect()) + hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(_lctx, b)).collect()) } TyMac(_) => panic!("TyMac should have been expanded by now."), }, @@ -133,14 +139,14 @@ pub fn lower_ty(t: &Ty) -> P { }) } -pub fn lower_foreign_mod(fm: &ForeignMod) -> hir::ForeignMod { +pub fn lower_foreign_mod(_lctx: &LoweringContext, fm: &ForeignMod) -> hir::ForeignMod { hir::ForeignMod { abi: fm.abi, - items: fm.items.iter().map(|x| lower_foreign_item(x)).collect(), + items: fm.items.iter().map(|x| lower_foreign_item(_lctx, x)).collect(), } } -pub fn lower_variant(v: &Variant) -> P { +pub fn lower_variant(_lctx: &LoweringContext, v: &Variant) -> P { P(Spanned { node: hir::Variant_ { id: v.node.id, @@ -148,117 +154,111 @@ pub fn lower_variant(v: &Variant) -> P { attrs: v.node.attrs.clone(), kind: match v.node.kind { TupleVariantKind(ref variant_args) => { - hir::TupleVariantKind(variant_args.iter() - .map(|ref x| lower_variant_arg(x)) - .collect()) + hir::TupleVariantKind(variant_args.iter().map(|ref x| + lower_variant_arg(_lctx, x)).collect()) } StructVariantKind(ref struct_def) => { - hir::StructVariantKind(lower_struct_def(struct_def)) + hir::StructVariantKind(lower_struct_def(_lctx, struct_def)) } }, - disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(e)), + disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(_lctx, e)), }, span: v.span, }) } -pub fn lower_path(p: &Path) -> hir::Path { +pub fn lower_path(_lctx: &LoweringContext, p: &Path) -> hir::Path { hir::Path { global: p.global, - segments: p.segments - .iter() - .map(|&PathSegment { identifier, ref parameters }| { - hir::PathSegment { - identifier: identifier, - parameters: lower_path_parameters(parameters), - } - }) - .collect(), + segments: p.segments.iter().map(|&PathSegment {identifier, ref parameters}| + hir::PathSegment { + identifier: identifier, + parameters: lower_path_parameters(_lctx, parameters), + }).collect(), span: p.span, } } -pub fn lower_path_parameters(path_parameters: &PathParameters) -> hir::PathParameters { +pub fn lower_path_parameters(_lctx: &LoweringContext, + path_parameters: &PathParameters) + -> hir::PathParameters { match *path_parameters { AngleBracketedParameters(ref data) => - hir::AngleBracketedParameters(lower_angle_bracketed_parameter_data(data)), + hir::AngleBracketedParameters(lower_angle_bracketed_parameter_data(_lctx, data)), ParenthesizedParameters(ref data) => - hir::ParenthesizedParameters(lower_parenthesized_parameter_data(data)), + hir::ParenthesizedParameters(lower_parenthesized_parameter_data(_lctx, data)), } } -pub fn lower_angle_bracketed_parameter_data(data: &AngleBracketedParameterData) +pub fn lower_angle_bracketed_parameter_data(_lctx: &LoweringContext, + data: &AngleBracketedParameterData) -> hir::AngleBracketedParameterData { let &AngleBracketedParameterData { ref lifetimes, ref types, ref bindings } = data; hir::AngleBracketedParameterData { - lifetimes: lower_lifetimes(lifetimes), - types: types.iter().map(|ty| lower_ty(ty)).collect(), - bindings: bindings.iter().map(|b| lower_ty_binding(b)).collect(), + lifetimes: lower_lifetimes(_lctx, lifetimes), + types: types.iter().map(|ty| lower_ty(_lctx, ty)).collect(), + bindings: bindings.iter().map(|b| lower_ty_binding(_lctx, b)).collect(), } } -pub fn lower_parenthesized_parameter_data(data: &ParenthesizedParameterData) +pub fn lower_parenthesized_parameter_data(_lctx: &LoweringContext, + data: &ParenthesizedParameterData) -> hir::ParenthesizedParameterData { let &ParenthesizedParameterData { ref inputs, ref output, span } = data; hir::ParenthesizedParameterData { - inputs: inputs.iter().map(|ty| lower_ty(ty)).collect(), - output: output.as_ref().map(|ty| lower_ty(ty)), + inputs: inputs.iter().map(|ty| lower_ty(_lctx, ty)).collect(), + output: output.as_ref().map(|ty| lower_ty(_lctx, ty)), span: span, } } -pub fn lower_local(l: &Local) -> P { +pub fn lower_local(_lctx: &LoweringContext, l: &Local) -> P { P(hir::Local { - id: l.id, - ty: l.ty.as_ref().map(|t| lower_ty(t)), - pat: lower_pat(&l.pat), - init: l.init.as_ref().map(|e| lower_expr(e)), - span: l.span, - }) + id: l.id, + ty: l.ty.as_ref().map(|t| lower_ty(_lctx, t)), + pat: lower_pat(_lctx, &l.pat), + init: l.init.as_ref().map(|e| lower_expr(_lctx, e)), + span: l.span, + }) } -pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ { +pub fn lower_explicit_self_underscore(_lctx: &LoweringContext, + es: &ExplicitSelf_) + -> hir::ExplicitSelf_ { match *es { SelfStatic => hir::SelfStatic, SelfValue(v) => hir::SelfValue(v.name), SelfRegion(ref lifetime, m, ident) => { - hir::SelfRegion(lower_opt_lifetime(lifetime), - lower_mutability(m), + hir::SelfRegion(lower_opt_lifetime(_lctx, lifetime), + lower_mutability(_lctx, m), ident.name) } SelfExplicit(ref typ, ident) => { - hir::SelfExplicit(lower_ty(typ), ident.name) + hir::SelfExplicit(lower_ty(_lctx, typ), ident.name) } } } -pub fn lower_mutability(m: Mutability) -> hir::Mutability { +pub fn lower_mutability(_lctx: &LoweringContext, m: Mutability) -> hir::Mutability { match m { MutMutable => hir::MutMutable, MutImmutable => hir::MutImmutable, } } -pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf { - Spanned { - node: lower_explicit_self_underscore(&s.node), - span: s.span, - } +pub fn lower_explicit_self(_lctx: &LoweringContext, s: &ExplicitSelf) -> hir::ExplicitSelf { + Spanned { node: lower_explicit_self_underscore(_lctx, &s.node), span: s.span } } -pub fn lower_arg(arg: &Arg) -> hir::Arg { - hir::Arg { - id: arg.id, - pat: lower_pat(&arg.pat), - ty: lower_ty(&arg.ty), - } +pub fn lower_arg(_lctx: &LoweringContext, arg: &Arg) -> hir::Arg { + hir::Arg { id: arg.id, pat: lower_pat(_lctx, &arg.pat), ty: lower_ty(_lctx, &arg.ty) } } -pub fn lower_fn_decl(decl: &FnDecl) -> P { +pub fn lower_fn_decl(_lctx: &LoweringContext, decl: &FnDecl) -> P { P(hir::FnDecl { - inputs: decl.inputs.iter().map(|x| lower_arg(x)).collect(), + inputs: decl.inputs.iter().map(|x| lower_arg(_lctx, x)).collect(), output: match decl.output { - Return(ref ty) => hir::Return(lower_ty(ty)), + Return(ref ty) => hir::Return(lower_ty(_lctx, ty)), DefaultReturn(span) => hir::DefaultReturn(span), NoReturn(span) => hir::NoReturn(span), }, @@ -266,86 +266,90 @@ pub fn lower_fn_decl(decl: &FnDecl) -> P { }) } -pub fn lower_ty_param_bound(tpb: &TyParamBound) -> hir::TyParamBound { +pub fn lower_ty_param_bound(_lctx: &LoweringContext, tpb: &TyParamBound) -> hir::TyParamBound { match *tpb { TraitTyParamBound(ref ty, modifier) => { - hir::TraitTyParamBound(lower_poly_trait_ref(ty), - lower_trait_bound_modifier(modifier)) + hir::TraitTyParamBound(lower_poly_trait_ref(_lctx, ty), + lower_trait_bound_modifier(_lctx, modifier)) + } + RegionTyParamBound(ref lifetime) => { + hir::RegionTyParamBound(lower_lifetime(_lctx, lifetime)) } - RegionTyParamBound(ref lifetime) => hir::RegionTyParamBound(lower_lifetime(lifetime)), } } -pub fn lower_ty_param(tp: &TyParam) -> hir::TyParam { +pub fn lower_ty_param(_lctx: &LoweringContext, tp: &TyParam) -> hir::TyParam { hir::TyParam { id: tp.id, name: tp.ident.name, - bounds: lower_bounds(&tp.bounds), - default: tp.default.as_ref().map(|x| lower_ty(x)), + bounds: lower_bounds(_lctx, &tp.bounds), + default: tp.default.as_ref().map(|x| lower_ty(_lctx, x)), span: tp.span, } } -pub fn lower_ty_params(tps: &OwnedSlice) -> OwnedSlice { - tps.iter().map(|tp| lower_ty_param(tp)).collect() +pub fn lower_ty_params(_lctx: &LoweringContext, + tps: &OwnedSlice) + -> OwnedSlice { + tps.iter().map(|tp| lower_ty_param(_lctx, tp)).collect() } -pub fn lower_lifetime(l: &Lifetime) -> hir::Lifetime { - hir::Lifetime { - id: l.id, - name: l.name, - span: l.span, - } +pub fn lower_lifetime(_lctx: &LoweringContext, l: &Lifetime) -> hir::Lifetime { + hir::Lifetime { id: l.id, name: l.name, span: l.span } } -pub fn lower_lifetime_def(l: &LifetimeDef) -> hir::LifetimeDef { +pub fn lower_lifetime_def(_lctx: &LoweringContext, l: &LifetimeDef) -> hir::LifetimeDef { hir::LifetimeDef { - lifetime: lower_lifetime(&l.lifetime), - bounds: lower_lifetimes(&l.bounds), + lifetime: lower_lifetime(_lctx, &l.lifetime), + bounds: lower_lifetimes(_lctx, &l.bounds) } } -pub fn lower_lifetimes(lts: &Vec) -> Vec { - lts.iter().map(|l| lower_lifetime(l)).collect() +pub fn lower_lifetimes(_lctx: &LoweringContext, lts: &Vec) -> Vec { + lts.iter().map(|l| lower_lifetime(_lctx, l)).collect() } -pub fn lower_lifetime_defs(lts: &Vec) -> Vec { - lts.iter().map(|l| lower_lifetime_def(l)).collect() +pub fn lower_lifetime_defs(_lctx: &LoweringContext, + lts: &Vec) + -> Vec { + lts.iter().map(|l| lower_lifetime_def(_lctx, l)).collect() } -pub fn lower_opt_lifetime(o_lt: &Option) -> Option { - o_lt.as_ref().map(|lt| lower_lifetime(lt)) +pub fn lower_opt_lifetime(_lctx: &LoweringContext, + o_lt: &Option) + -> Option { + o_lt.as_ref().map(|lt| lower_lifetime(_lctx, lt)) } -pub fn lower_generics(g: &Generics) -> hir::Generics { +pub fn lower_generics(_lctx: &LoweringContext, g: &Generics) -> hir::Generics { hir::Generics { - ty_params: lower_ty_params(&g.ty_params), - lifetimes: lower_lifetime_defs(&g.lifetimes), - where_clause: lower_where_clause(&g.where_clause), + ty_params: lower_ty_params(_lctx, &g.ty_params), + lifetimes: lower_lifetime_defs(_lctx, &g.lifetimes), + where_clause: lower_where_clause(_lctx, &g.where_clause), } } -pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause { +pub fn lower_where_clause(_lctx: &LoweringContext, wc: &WhereClause) -> hir::WhereClause { hir::WhereClause { id: wc.id, - predicates: wc.predicates - .iter() - .map(|predicate| lower_where_predicate(predicate)) - .collect(), + predicates: wc.predicates.iter().map(|predicate| + lower_where_predicate(_lctx, predicate)).collect(), } } -pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate { +pub fn lower_where_predicate(_lctx: &LoweringContext, + pred: &WherePredicate) + -> hir::WherePredicate { match *pred { WherePredicate::BoundPredicate(WhereBoundPredicate{ ref bound_lifetimes, ref bounded_ty, ref bounds, span}) => { hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate { - bound_lifetimes: lower_lifetime_defs(bound_lifetimes), - bounded_ty: lower_ty(bounded_ty), - bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(), - span: span, + bound_lifetimes: lower_lifetime_defs(_lctx, bound_lifetimes), + bounded_ty: lower_ty(_lctx, bounded_ty), + bounds: bounds.iter().map(|x| lower_ty_param_bound(_lctx, x)).collect(), + span: span }) } WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime, @@ -353,8 +357,8 @@ pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate { span}) => { hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate { span: span, - lifetime: lower_lifetime(lifetime), - bounds: bounds.iter().map(|bound| lower_lifetime(bound)).collect(), + lifetime: lower_lifetime(_lctx, lifetime), + bounds: bounds.iter().map(|bound| lower_lifetime(_lctx, bound)).collect() }) } WherePredicate::EqPredicate(WhereEqPredicate{ id, @@ -363,145 +367,138 @@ pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate { span}) => { hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { id: id, - path: lower_path(path), - ty: lower_ty(ty), - span: span, + path: lower_path(_lctx, path), + ty:lower_ty(_lctx, ty), + span: span }) } } } -pub fn lower_struct_def(sd: &StructDef) -> P { +pub fn lower_struct_def(_lctx: &LoweringContext, sd: &StructDef) -> P { P(hir::StructDef { - fields: sd.fields.iter().map(|f| lower_struct_field(f)).collect(), + fields: sd.fields.iter().map(|f| lower_struct_field(_lctx, f)).collect(), ctor_id: sd.ctor_id, }) } -pub fn lower_trait_ref(p: &TraitRef) -> hir::TraitRef { - hir::TraitRef { - path: lower_path(&p.path), - ref_id: p.ref_id, - } +pub fn lower_trait_ref(_lctx: &LoweringContext, p: &TraitRef) -> hir::TraitRef { + hir::TraitRef { path: lower_path(_lctx, &p.path), ref_id: p.ref_id } } -pub fn lower_poly_trait_ref(p: &PolyTraitRef) -> hir::PolyTraitRef { +pub fn lower_poly_trait_ref(_lctx: &LoweringContext, p: &PolyTraitRef) -> hir::PolyTraitRef { hir::PolyTraitRef { - bound_lifetimes: lower_lifetime_defs(&p.bound_lifetimes), - trait_ref: lower_trait_ref(&p.trait_ref), + bound_lifetimes: lower_lifetime_defs(_lctx, &p.bound_lifetimes), + trait_ref: lower_trait_ref(_lctx, &p.trait_ref), span: p.span, } } -pub fn lower_struct_field(f: &StructField) -> hir::StructField { +pub fn lower_struct_field(_lctx: &LoweringContext, f: &StructField) -> hir::StructField { Spanned { node: hir::StructField_ { id: f.node.id, - kind: lower_struct_field_kind(&f.node.kind), - ty: lower_ty(&f.node.ty), + kind: lower_struct_field_kind(_lctx, &f.node.kind), + ty: lower_ty(_lctx, &f.node.ty), attrs: f.node.attrs.clone(), }, span: f.span, } } -pub fn lower_field(f: &Field) -> hir::Field { +pub fn lower_field(_lctx: &LoweringContext, f: &Field) -> hir::Field { hir::Field { name: respan(f.ident.span, f.ident.node.name), - expr: lower_expr(&f.expr), - span: f.span, + expr: lower_expr(_lctx, &f.expr), span: f.span } } -pub fn lower_mt(mt: &MutTy) -> hir::MutTy { - hir::MutTy { - ty: lower_ty(&mt.ty), - mutbl: lower_mutability(mt.mutbl), - } +pub fn lower_mt(_lctx: &LoweringContext, mt: &MutTy) -> hir::MutTy { + hir::MutTy { ty: lower_ty(_lctx, &mt.ty), mutbl: lower_mutability(_lctx, mt.mutbl) } } -pub fn lower_opt_bounds(b: &Option>) +pub fn lower_opt_bounds(_lctx: &LoweringContext, b: &Option>) -> Option> { - b.as_ref().map(|ref bounds| lower_bounds(bounds)) + b.as_ref().map(|ref bounds| lower_bounds(_lctx, bounds)) } -fn lower_bounds(bounds: &TyParamBounds) -> hir::TyParamBounds { - bounds.iter().map(|bound| lower_ty_param_bound(bound)).collect() +fn lower_bounds(_lctx: &LoweringContext, bounds: &TyParamBounds) -> hir::TyParamBounds { + bounds.iter().map(|bound| lower_ty_param_bound(_lctx, bound)).collect() } -fn lower_variant_arg(va: &VariantArg) -> hir::VariantArg { - hir::VariantArg { - id: va.id, - ty: lower_ty(&va.ty), - } +fn lower_variant_arg(_lctx: &LoweringContext, va: &VariantArg) -> hir::VariantArg { + hir::VariantArg { id: va.id, ty: lower_ty(_lctx, &va.ty) } } -pub fn lower_block(b: &Block) -> P { +pub fn lower_block(_lctx: &LoweringContext, b: &Block) -> P { P(hir::Block { id: b.id, - stmts: b.stmts.iter().map(|s| lower_stmt(s)).collect(), - expr: b.expr.as_ref().map(|ref x| lower_expr(x)), - rules: lower_block_check_mode(&b.rules), + stmts: b.stmts.iter().map(|s| lower_stmt(_lctx, s)).collect(), + expr: b.expr.as_ref().map(|ref x| lower_expr(_lctx, x)), + rules: lower_block_check_mode(_lctx, &b.rules), span: b.span, }) } -pub fn lower_item_underscore(i: &Item_) -> hir::Item_ { +pub fn lower_item_underscore(_lctx: &LoweringContext, i: &Item_) -> hir::Item_ { match *i { ItemExternCrate(string) => hir::ItemExternCrate(string), ItemUse(ref view_path) => { - hir::ItemUse(lower_view_path(view_path)) + hir::ItemUse(lower_view_path(_lctx, view_path)) } ItemStatic(ref t, m, ref e) => { - hir::ItemStatic(lower_ty(t), lower_mutability(m), lower_expr(e)) + hir::ItemStatic(lower_ty(_lctx, t), lower_mutability(_lctx, m), lower_expr(_lctx, e)) } ItemConst(ref t, ref e) => { - hir::ItemConst(lower_ty(t), lower_expr(e)) + hir::ItemConst(lower_ty(_lctx, t), lower_expr(_lctx, e)) } ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => { - hir::ItemFn(lower_fn_decl(decl), - lower_unsafety(unsafety), - lower_constness(constness), - abi, - lower_generics(generics), - lower_block(body)) + hir::ItemFn( + lower_fn_decl(_lctx, decl), + lower_unsafety(_lctx, unsafety), + lower_constness(_lctx, constness), + abi, + lower_generics(_lctx, generics), + lower_block(_lctx, body) + ) } - ItemMod(ref m) => hir::ItemMod(lower_mod(m)), - ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)), + ItemMod(ref m) => hir::ItemMod(lower_mod(_lctx, m)), + ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(_lctx, nm)), ItemTy(ref t, ref generics) => { - hir::ItemTy(lower_ty(t), lower_generics(generics)) + hir::ItemTy(lower_ty(_lctx, t), lower_generics(_lctx, generics)) } ItemEnum(ref enum_definition, ref generics) => { - hir::ItemEnum(hir::EnumDef { - variants: enum_definition.variants - .iter() - .map(|x| lower_variant(x)) - .collect(), - }, - lower_generics(generics)) + hir::ItemEnum( + hir::EnumDef { + variants: enum_definition.variants.iter().map(|x| { + lower_variant(_lctx, x) + }).collect(), + }, + lower_generics(_lctx, generics)) } ItemStruct(ref struct_def, ref generics) => { - let struct_def = lower_struct_def(struct_def); - hir::ItemStruct(struct_def, lower_generics(generics)) + let struct_def = lower_struct_def(_lctx, struct_def); + hir::ItemStruct(struct_def, lower_generics(_lctx, generics)) } ItemDefaultImpl(unsafety, ref trait_ref) => { - hir::ItemDefaultImpl(lower_unsafety(unsafety), lower_trait_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) => { - let new_impl_items = impl_items.iter().map(|item| lower_impl_item(item)).collect(); - let ifce = ifce.as_ref().map(|trait_ref| lower_trait_ref(trait_ref)); - hir::ItemImpl(lower_unsafety(unsafety), - lower_impl_polarity(polarity), - lower_generics(generics), + let new_impl_items = + impl_items.iter().map(|item| lower_impl_item(_lctx, item)).collect(); + let ifce = ifce.as_ref().map(|trait_ref| lower_trait_ref(_lctx, trait_ref)); + hir::ItemImpl(lower_unsafety(_lctx, unsafety), + lower_impl_polarity(_lctx, polarity), + lower_generics(_lctx, generics), ifce, - lower_ty(ty), + lower_ty(_lctx, ty), new_impl_items) } ItemTrait(unsafety, ref generics, ref bounds, ref items) => { - let bounds = lower_bounds(bounds); - let items = items.iter().map(|item| lower_trait_item(item)).collect(); - hir::ItemTrait(lower_unsafety(unsafety), - lower_generics(generics), + let bounds = lower_bounds(_lctx, bounds); + let items = items.iter().map(|item| lower_trait_item(_lctx, item)).collect(); + hir::ItemTrait(lower_unsafety(_lctx, unsafety), + lower_generics(_lctx, generics), bounds, items) } @@ -509,67 +506,65 @@ pub fn lower_item_underscore(i: &Item_) -> hir::Item_ { } } -pub fn lower_trait_item(i: &TraitItem) -> P { +pub fn lower_trait_item(_lctx: &LoweringContext, i: &TraitItem) -> P { P(hir::TraitItem { id: i.id, name: i.ident.name, attrs: i.attrs.clone(), node: match i.node { ConstTraitItem(ref ty, ref default) => { - hir::ConstTraitItem(lower_ty(ty), - default.as_ref().map(|x| lower_expr(x))) + hir::ConstTraitItem(lower_ty(_lctx, ty), + default.as_ref().map(|x| lower_expr(_lctx, x))) } MethodTraitItem(ref sig, ref body) => { - hir::MethodTraitItem(lower_method_sig(sig), - body.as_ref().map(|x| lower_block(x))) + hir::MethodTraitItem(lower_method_sig(_lctx, sig), + body.as_ref().map(|x| lower_block(_lctx, x))) } TypeTraitItem(ref bounds, ref default) => { - hir::TypeTraitItem(lower_bounds(bounds), - default.as_ref().map(|x| lower_ty(x))) + hir::TypeTraitItem(lower_bounds(_lctx, bounds), + default.as_ref().map(|x| lower_ty(_lctx, x))) } }, span: i.span, }) } -pub fn lower_impl_item(i: &ImplItem) -> P { +pub fn lower_impl_item(_lctx: &LoweringContext, i: &ImplItem) -> P { P(hir::ImplItem { - id: i.id, - name: i.ident.name, - attrs: i.attrs.clone(), - vis: lower_visibility(i.vis), - node: match i.node { + id: i.id, + name: i.ident.name, + attrs: i.attrs.clone(), + vis: lower_visibility(_lctx, i.vis), + node: match i.node { ConstImplItem(ref ty, ref expr) => { - hir::ConstImplItem(lower_ty(ty), lower_expr(expr)) + hir::ConstImplItem(lower_ty(_lctx, ty), lower_expr(_lctx, expr)) } MethodImplItem(ref sig, ref body) => { - hir::MethodImplItem(lower_method_sig(sig), lower_block(body)) + hir::MethodImplItem(lower_method_sig(_lctx, sig), + lower_block(_lctx, body)) } - TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)), + TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(_lctx, ty)), MacImplItem(..) => panic!("Shouldn't exist any more"), }, span: i.span, }) } -pub fn lower_mod(m: &Mod) -> hir::Mod { - hir::Mod { - inner: m.inner, - items: m.items.iter().map(|x| lower_item(x)).collect(), - } +pub fn lower_mod(_lctx: &LoweringContext, m: &Mod) -> hir::Mod { + hir::Mod { inner: m.inner, items: m.items.iter().map(|x| lower_item(_lctx, x)).collect() } } -pub fn lower_crate(c: &Crate) -> hir::Crate { +pub fn lower_crate(_lctx: &LoweringContext, c: &Crate) -> hir::Crate { hir::Crate { - module: lower_mod(&c.module), + module: lower_mod(_lctx, &c.module), attrs: c.attrs.clone(), config: c.config.clone(), span: c.span, - exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(m)).collect(), + exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(_lctx, m)).collect(), } } -pub fn lower_macro_def(m: &MacroDef) -> hir::MacroDef { +pub fn lower_macro_def(_lctx: &LoweringContext, m: &MacroDef) -> hir::MacroDef { hir::MacroDef { name: m.ident.name, attrs: m.attrs.clone(), @@ -584,68 +579,68 @@ pub fn lower_macro_def(m: &MacroDef) -> hir::MacroDef { } // fold one item into possibly many items -pub fn lower_item(i: &Item) -> P { - P(lower_item_simple(i)) +pub fn lower_item(_lctx: &LoweringContext, i: &Item) -> P { + P(lower_item_simple(_lctx, i)) } // fold one item into exactly one item -pub fn lower_item_simple(i: &Item) -> hir::Item { - let node = lower_item_underscore(&i.node); +pub fn lower_item_simple(_lctx: &LoweringContext, i: &Item) -> hir::Item { + let node = lower_item_underscore(_lctx, &i.node); hir::Item { id: i.id, name: i.ident.name, attrs: i.attrs.clone(), node: node, - vis: lower_visibility(i.vis), + vis: lower_visibility(_lctx, i.vis), span: i.span, } } -pub fn lower_foreign_item(i: &ForeignItem) -> P { +pub fn lower_foreign_item(_lctx: &LoweringContext, i: &ForeignItem) -> P { P(hir::ForeignItem { id: i.id, name: i.ident.name, attrs: i.attrs.clone(), node: match i.node { ForeignItemFn(ref fdec, ref generics) => { - hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics)) + hir::ForeignItemFn(lower_fn_decl(_lctx, fdec), lower_generics(_lctx, generics)) } ForeignItemStatic(ref t, m) => { - hir::ForeignItemStatic(lower_ty(t), m) + hir::ForeignItemStatic(lower_ty(_lctx, t), m) } }, - vis: lower_visibility(i.vis), - span: i.span, - }) + vis: lower_visibility(_lctx, i.vis), + span: i.span, + }) } -pub fn lower_method_sig(sig: &MethodSig) -> hir::MethodSig { +pub fn lower_method_sig(_lctx: &LoweringContext, sig: &MethodSig) -> hir::MethodSig { hir::MethodSig { - generics: lower_generics(&sig.generics), + generics: lower_generics(_lctx, &sig.generics), abi: sig.abi, - explicit_self: lower_explicit_self(&sig.explicit_self), - unsafety: lower_unsafety(sig.unsafety), - constness: lower_constness(sig.constness), - decl: lower_fn_decl(&sig.decl), + explicit_self: lower_explicit_self(_lctx, &sig.explicit_self), + unsafety: lower_unsafety(_lctx, sig.unsafety), + constness: lower_constness(_lctx, sig.constness), + decl: lower_fn_decl(_lctx, &sig.decl), } } -pub fn lower_unsafety(u: Unsafety) -> hir::Unsafety { +pub fn lower_unsafety(_lctx: &LoweringContext, u: Unsafety) -> hir::Unsafety { match u { Unsafety::Unsafe => hir::Unsafety::Unsafe, Unsafety::Normal => hir::Unsafety::Normal, } } -pub fn lower_constness(c: Constness) -> hir::Constness { +pub fn lower_constness(_lctx: &LoweringContext, c: Constness) -> hir::Constness { match c { Constness::Const => hir::Constness::Const, Constness::NotConst => hir::Constness::NotConst, } } -pub fn lower_unop(u: UnOp) -> hir::UnOp { +pub fn lower_unop(_lctx: &LoweringContext, u: UnOp) -> hir::UnOp { match u { UnDeref => hir::UnDeref, UnNot => hir::UnNot, @@ -653,7 +648,7 @@ pub fn lower_unop(u: UnOp) -> hir::UnOp { } } -pub fn lower_binop(b: BinOp) -> hir::BinOp { +pub fn lower_binop(_lctx: &LoweringContext, b: BinOp) -> hir::BinOp { Spanned { node: match b.node { BiAdd => hir::BiAdd, @@ -679,55 +674,52 @@ pub fn lower_binop(b: BinOp) -> hir::BinOp { } } -pub fn lower_pat(p: &Pat) -> P { +pub fn lower_pat(_lctx: &LoweringContext, p: &Pat) -> P { P(hir::Pat { - id: p.id, - node: match p.node { - PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)), + id: p.id, + node: match p.node { + PatWild(k) => hir::PatWild(lower_pat_wild_kind(_lctx, k)), PatIdent(ref binding_mode, pth1, ref sub) => { - hir::PatIdent(lower_binding_mode(binding_mode), - pth1, - sub.as_ref().map(|x| lower_pat(x))) + hir::PatIdent(lower_binding_mode(_lctx, binding_mode), + pth1, + sub.as_ref().map(|x| lower_pat(_lctx, x))) } - PatLit(ref e) => hir::PatLit(lower_expr(e)), + PatLit(ref e) => hir::PatLit(lower_expr(_lctx, e)), PatEnum(ref pth, ref pats) => { - hir::PatEnum(lower_path(pth), - pats.as_ref().map(|pats| pats.iter().map(|x| lower_pat(x)).collect())) + hir::PatEnum(lower_path(_lctx, pth), + pats.as_ref() + .map(|pats| pats.iter().map(|x| lower_pat(_lctx, x)).collect())) } PatQPath(ref qself, ref pth) => { let qself = hir::QSelf { - ty: lower_ty(&qself.ty), + ty: lower_ty(_lctx, &qself.ty), position: qself.position, }; - hir::PatQPath(qself, lower_path(pth)) + hir::PatQPath(qself, lower_path(_lctx, pth)) } PatStruct(ref pth, ref fields, etc) => { - let pth = lower_path(pth); - let fs = fields.iter() - .map(|f| { - Spanned { - span: f.span, - node: hir::FieldPat { - name: f.node.ident.name, - pat: lower_pat(&f.node.pat), - is_shorthand: f.node.is_shorthand, - }, - } - }) - .collect(); + let pth = lower_path(_lctx, pth); + let fs = fields.iter().map(|f| { + Spanned { span: f.span, + node: hir::FieldPat { + name: f.node.ident.name, + pat: lower_pat(_lctx, &f.node.pat), + is_shorthand: f.node.is_shorthand, + }} + }).collect(); hir::PatStruct(pth, fs, etc) } - PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()), - PatBox(ref inner) => hir::PatBox(lower_pat(inner)), - PatRegion(ref inner, mutbl) => - hir::PatRegion(lower_pat(inner), lower_mutability(mutbl)), + PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(_lctx, x)).collect()), + PatBox(ref inner) => hir::PatBox(lower_pat(_lctx, inner)), + PatRegion(ref inner, mutbl) => hir::PatRegion(lower_pat(_lctx, inner), + lower_mutability(_lctx, mutbl)), PatRange(ref e1, ref e2) => { - hir::PatRange(lower_expr(e1), lower_expr(e2)) - } + hir::PatRange(lower_expr(_lctx, e1), lower_expr(_lctx, e2)) + }, PatVec(ref before, ref slice, ref after) => { - hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(), - slice.as_ref().map(|x| lower_pat(x)), - after.iter().map(|x| lower_pat(x)).collect()) + hir::PatVec(before.iter().map(|x| lower_pat(_lctx, x)).collect(), + slice.as_ref().map(|x| lower_pat(_lctx, x)), + after.iter().map(|x| lower_pat(_lctx, x)).collect()) } PatMac(_) => panic!("Shouldn't exist here"), }, @@ -735,94 +727,106 @@ pub fn lower_pat(p: &Pat) -> P { }) } -pub fn lower_expr(e: &Expr) -> P { +pub fn lower_expr(_lctx: &LoweringContext, e: &Expr) -> P { P(hir::Expr { - id: e.id, - node: match e.node { - ExprBox(ref e) => { - hir::ExprBox(lower_expr(e)) - } - ExprVec(ref exprs) => { - hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect()) - } - ExprRepeat(ref expr, ref count) => { - hir::ExprRepeat(lower_expr(expr), lower_expr(count)) - } - ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()), - ExprCall(ref f, ref args) => { - hir::ExprCall(lower_expr(f), - args.iter().map(|x| lower_expr(x)).collect()) - } - ExprMethodCall(i, ref tps, ref args) => { - hir::ExprMethodCall(respan(i.span, i.node.name), - tps.iter().map(|x| lower_ty(x)).collect(), - args.iter().map(|x| lower_expr(x)).collect()) - } - ExprBinary(binop, ref lhs, ref rhs) => { - hir::ExprBinary(lower_binop(binop), lower_expr(lhs), lower_expr(rhs)) - } - ExprUnary(op, ref ohs) => { - hir::ExprUnary(lower_unop(op), lower_expr(ohs)) - } - ExprLit(ref l) => hir::ExprLit(P((**l).clone())), - ExprCast(ref expr, ref ty) => { - hir::ExprCast(lower_expr(expr), lower_ty(ty)) - } - ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)), - ExprIf(ref cond, ref tr, ref fl) => { - hir::ExprIf(lower_expr(cond), - lower_block(tr), - fl.as_ref().map(|x| lower_expr(x))) - } - ExprWhile(ref cond, ref body, opt_ident) => { - hir::ExprWhile(lower_expr(cond), lower_block(body), opt_ident) - } - ExprLoop(ref body, opt_ident) => { - hir::ExprLoop(lower_block(body), opt_ident) - } - ExprMatch(ref expr, ref arms, ref source) => { - hir::ExprMatch(lower_expr(expr), - arms.iter().map(|x| lower_arm(x)).collect(), - lower_match_source(source)) - } - ExprClosure(capture_clause, ref decl, ref body) => { - hir::ExprClosure(lower_capture_clause(capture_clause), - lower_fn_decl(decl), - lower_block(body)) - } - ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)), - ExprAssign(ref el, ref er) => { - hir::ExprAssign(lower_expr(el), lower_expr(er)) - } - ExprAssignOp(op, ref el, ref er) => { - hir::ExprAssignOp(lower_binop(op), lower_expr(el), lower_expr(er)) - } - ExprField(ref el, ident) => { - hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name)) - } - ExprTupField(ref el, ident) => { - hir::ExprTupField(lower_expr(el), ident) - } - ExprIndex(ref el, ref er) => { - hir::ExprIndex(lower_expr(el), lower_expr(er)) - } - ExprRange(ref e1, ref e2) => { - hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)), - e2.as_ref().map(|x| lower_expr(x))) - } - ExprPath(ref qself, ref path) => { - let qself = qself.as_ref().map(|&QSelf { ref ty, position }| { - hir::QSelf { - ty: lower_ty(ty), - position: position, - } - }); - hir::ExprPath(qself, lower_path(path)) - } - ExprBreak(opt_ident) => hir::ExprBreak(opt_ident), - ExprAgain(opt_ident) => hir::ExprAgain(opt_ident), - ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(x))), - ExprInlineAsm(InlineAsm { + id: e.id, + node: match e.node { + ExprBox(ref e) => { + hir::ExprBox(lower_expr(_lctx, e)) + } + ExprVec(ref exprs) => { + hir::ExprVec(exprs.iter().map(|x| lower_expr(_lctx, x)).collect()) + } + ExprRepeat(ref expr, ref count) => { + hir::ExprRepeat(lower_expr(_lctx, expr), lower_expr(_lctx, count)) + } + ExprTup(ref elts) => { + hir::ExprTup(elts.iter().map(|x| lower_expr(_lctx, x)).collect()) + } + ExprCall(ref f, ref args) => { + hir::ExprCall(lower_expr(_lctx, f), + args.iter().map(|x| lower_expr(_lctx, x)).collect()) + } + ExprMethodCall(i, ref tps, ref args) => { + hir::ExprMethodCall( + respan(i.span, i.node.name), + tps.iter().map(|x| lower_ty(_lctx, x)).collect(), + args.iter().map(|x| lower_expr(_lctx, x)).collect()) + } + ExprBinary(binop, ref lhs, ref rhs) => { + hir::ExprBinary(lower_binop(_lctx, binop), + lower_expr(_lctx, lhs), + lower_expr(_lctx, rhs)) + } + ExprUnary(op, ref ohs) => { + hir::ExprUnary(lower_unop(_lctx, op), lower_expr(_lctx, ohs)) + } + ExprLit(ref l) => hir::ExprLit(P((**l).clone())), + ExprCast(ref expr, ref ty) => { + hir::ExprCast(lower_expr(_lctx, expr), lower_ty(_lctx, ty)) + } + ExprAddrOf(m, ref ohs) => { + hir::ExprAddrOf(lower_mutability(_lctx, m), lower_expr(_lctx, ohs)) + } + ExprIf(ref cond, ref tr, ref fl) => { + hir::ExprIf(lower_expr(_lctx, cond), + lower_block(_lctx, tr), + fl.as_ref().map(|x| lower_expr(_lctx, x))) + } + ExprWhile(ref cond, ref body, opt_ident) => { + hir::ExprWhile(lower_expr(_lctx, cond), + lower_block(_lctx, body), + opt_ident) + } + ExprLoop(ref body, opt_ident) => { + hir::ExprLoop(lower_block(_lctx, body), + opt_ident) + } + ExprMatch(ref expr, ref arms, ref source) => { + hir::ExprMatch(lower_expr(_lctx, expr), + arms.iter().map(|x| lower_arm(_lctx, x)).collect(), + lower_match_source(_lctx, source)) + } + ExprClosure(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) => { + hir::ExprAssign(lower_expr(_lctx, el), lower_expr(_lctx, er)) + } + ExprAssignOp(op, ref el, ref er) => { + hir::ExprAssignOp(lower_binop(_lctx, op), + lower_expr(_lctx, el), + lower_expr(_lctx, er)) + } + ExprField(ref el, ident) => { + hir::ExprField(lower_expr(_lctx, el), respan(ident.span, ident.node.name)) + } + ExprTupField(ref el, ident) => { + hir::ExprTupField(lower_expr(_lctx, el), ident) + } + ExprIndex(ref el, ref er) => { + hir::ExprIndex(lower_expr(_lctx, el), lower_expr(_lctx, er)) + } + ExprRange(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) => { + let qself = qself.as_ref().map(|&QSelf { ref ty, position }| { + hir::QSelf { + ty: lower_ty(_lctx, ty), + position: position + } + }); + hir::ExprPath(qself, lower_path(_lctx, path)) + } + ExprBreak(opt_ident) => hir::ExprBreak(opt_ident), + ExprAgain(opt_ident) => hir::ExprAgain(opt_ident), + ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(_lctx, x))), + ExprInlineAsm(InlineAsm { ref inputs, ref outputs, ref asm, @@ -833,65 +837,63 @@ pub fn lower_expr(e: &Expr) -> P { dialect, expn_id, }) => hir::ExprInlineAsm(hir::InlineAsm { - inputs: inputs.iter() - .map(|&(ref c, ref input)| (c.clone(), lower_expr(input))) - .collect(), - outputs: outputs.iter() - .map(|&(ref c, ref out, ref is_rw)| { - (c.clone(), lower_expr(out), *is_rw) - }) - .collect(), - asm: asm.clone(), - asm_str_style: asm_str_style, - clobbers: clobbers.clone(), - volatile: volatile, - alignstack: alignstack, - dialect: dialect, - expn_id: expn_id, - }), - ExprStruct(ref path, ref fields, ref maybe_expr) => { - hir::ExprStruct(lower_path(path), - fields.iter().map(|x| lower_field(x)).collect(), - maybe_expr.as_ref().map(|x| lower_expr(x))) - } - ExprParen(ref ex) => { - return lower_expr(ex); - } - ExprInPlace(..) | - ExprIfLet(..) | - ExprWhileLet(..) | - ExprForLoop(..) | - ExprMac(_) => panic!("Shouldn't exist here"), - }, - span: e.span, - }) + inputs: inputs.iter().map(|&(ref c, ref input)| { + (c.clone(), lower_expr(_lctx, input)) + }).collect(), + outputs: outputs.iter().map(|&(ref c, ref out, ref is_rw)| { + (c.clone(), lower_expr(_lctx, out), *is_rw) + }).collect(), + asm: asm.clone(), + asm_str_style: asm_str_style, + clobbers: clobbers.clone(), + volatile: volatile, + alignstack: alignstack, + dialect: dialect, + expn_id: expn_id, + }), + ExprStruct(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) => { + return lower_expr(_lctx, ex); + } + ExprInPlace(..) | + ExprIfLet(..) | + ExprWhileLet(..) | + ExprForLoop(..) | + ExprMac(_) => panic!("Shouldn't exist here"), + }, + span: e.span, + }) } -pub fn lower_stmt(s: &Stmt) -> P { +pub fn lower_stmt(_lctx: &LoweringContext, s: &Stmt) -> P { match s.node { StmtDecl(ref d, id) => { P(Spanned { - node: hir::StmtDecl(lower_decl(d), id), - span: s.span, + node: hir::StmtDecl(lower_decl(_lctx, d), id), + span: s.span }) } StmtExpr(ref e, id) => { P(Spanned { - node: hir::StmtExpr(lower_expr(e), id), - span: s.span, + node: hir::StmtExpr(lower_expr(_lctx, e), id), + span: s.span }) } StmtSemi(ref e, id) => { P(Spanned { - node: hir::StmtSemi(lower_expr(e), id), - span: s.span, + node: hir::StmtSemi(lower_expr(_lctx, e), id), + span: s.span }) } StmtMac(..) => panic!("Shouldn't exist here"), } } -pub fn lower_match_source(m: &MatchSource) -> hir::MatchSource { +pub fn lower_match_source(_lctx: &LoweringContext, m: &MatchSource) -> hir::MatchSource { match *m { MatchSource::Normal => hir::MatchSource::Normal, MatchSource::IfLetDesugar { contains_else_clause } => { @@ -902,65 +904,69 @@ pub fn lower_match_source(m: &MatchSource) -> hir::MatchSource { } } -pub fn lower_capture_clause(c: CaptureClause) -> hir::CaptureClause { +pub fn lower_capture_clause(_lctx: &LoweringContext, c: CaptureClause) -> hir::CaptureClause { match c { CaptureByValue => hir::CaptureByValue, CaptureByRef => hir::CaptureByRef, } } -pub fn lower_visibility(v: Visibility) -> hir::Visibility { +pub fn lower_visibility(_lctx: &LoweringContext, v: Visibility) -> hir::Visibility { match v { Public => hir::Public, Inherited => hir::Inherited, } } -pub fn lower_block_check_mode(b: &BlockCheckMode) -> hir::BlockCheckMode { +pub fn lower_block_check_mode(_lctx: &LoweringContext, b: &BlockCheckMode) -> hir::BlockCheckMode { match *b { DefaultBlock => hir::DefaultBlock, - UnsafeBlock(u) => hir::UnsafeBlock(lower_unsafe_source(u)), - PushUnsafeBlock(u) => hir::PushUnsafeBlock(lower_unsafe_source(u)), - PopUnsafeBlock(u) => hir::PopUnsafeBlock(lower_unsafe_source(u)), + UnsafeBlock(u) => hir::UnsafeBlock(lower_unsafe_source(_lctx, u)), + PushUnsafeBlock(u) => hir::PushUnsafeBlock(lower_unsafe_source(_lctx, u)), + PopUnsafeBlock(u) => hir::PopUnsafeBlock(lower_unsafe_source(_lctx, u)), } } -pub fn lower_pat_wild_kind(p: PatWildKind) -> hir::PatWildKind { +pub fn lower_pat_wild_kind(_lctx: &LoweringContext, p: PatWildKind) -> hir::PatWildKind { match p { PatWildSingle => hir::PatWildSingle, PatWildMulti => hir::PatWildMulti, } } -pub fn lower_binding_mode(b: &BindingMode) -> hir::BindingMode { +pub fn lower_binding_mode(_lctx: &LoweringContext, b: &BindingMode) -> hir::BindingMode { match *b { - BindByRef(m) => hir::BindByRef(lower_mutability(m)), - BindByValue(m) => hir::BindByValue(lower_mutability(m)), + BindByRef(m) => hir::BindByRef(lower_mutability(_lctx, m)), + BindByValue(m) => hir::BindByValue(lower_mutability(_lctx, m)), } } -pub fn lower_struct_field_kind(s: &StructFieldKind) -> hir::StructFieldKind { +pub fn lower_struct_field_kind(_lctx: &LoweringContext, + s: &StructFieldKind) + -> hir::StructFieldKind { match *s { - NamedField(ident, vis) => hir::NamedField(ident.name, lower_visibility(vis)), - UnnamedField(vis) => hir::UnnamedField(lower_visibility(vis)), + NamedField(ident, vis) => hir::NamedField(ident.name, lower_visibility(_lctx, vis)), + UnnamedField(vis) => hir::UnnamedField(lower_visibility(_lctx, vis)), } } -pub fn lower_unsafe_source(u: UnsafeSource) -> hir::UnsafeSource { +pub fn lower_unsafe_source(_lctx: &LoweringContext, u: UnsafeSource) -> hir::UnsafeSource { match u { CompilerGenerated => hir::CompilerGenerated, UserProvided => hir::UserProvided, } } -pub fn lower_impl_polarity(i: ImplPolarity) -> hir::ImplPolarity { +pub fn lower_impl_polarity(_lctx: &LoweringContext, i: ImplPolarity) -> hir::ImplPolarity { match i { ImplPolarity::Positive => hir::ImplPolarity::Positive, ImplPolarity::Negative => hir::ImplPolarity::Negative, } } -pub fn lower_trait_bound_modifier(f: TraitBoundModifier) -> hir::TraitBoundModifier { +pub fn lower_trait_bound_modifier(_lctx: &LoweringContext, + f: TraitBoundModifier) + -> hir::TraitBoundModifier { match f { TraitBoundModifier::None => hir::TraitBoundModifier::None, TraitBoundModifier::Maybe => hir::TraitBoundModifier::Maybe, diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index ae85730a876..296dd44a9bc 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -47,7 +47,7 @@ use syntax::visit::{self, Visitor}; use syntax::print::pprust::{path_to_string, ty_to_string}; use syntax::ptr::P; -use rustc_front::lowering::lower_expr; +use rustc_front::lowering::{lower_expr, LoweringContext}; use super::span_utils::SpanUtils; use super::recorder::{Recorder, FmtStrs}; @@ -76,6 +76,7 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> { impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> { pub fn new(tcx: &'l ty::ctxt<'tcx>, + lcx: &'l LoweringContext<'tcx>, analysis: &'l ty::CrateAnalysis, output_file: Box) -> DumpCsvVisitor<'l, 'tcx> { @@ -83,7 +84,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> { DumpCsvVisitor { sess: &tcx.sess, tcx: tcx, - save_ctxt: SaveContext::from_span_utils(tcx, span_utils.clone()), + save_ctxt: SaveContext::from_span_utils(tcx, lcx, span_utils.clone()), analysis: analysis, span: span_utils.clone(), fmt: FmtStrs::new(box Recorder { @@ -1035,7 +1036,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { visit::walk_expr(self, ex); } ast::ExprStruct(ref path, ref fields, ref base) => { - let hir_expr = lower_expr(ex); + let hir_expr = lower_expr(self.save_ctxt.lcx, ex); let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap(); let def = self.tcx.resolve_expr(&hir_expr); self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base) @@ -1064,7 +1065,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { self.visit_expr(&**sub_ex); - let hir_node = lower_expr(sub_ex); + let hir_node = lower_expr(self.save_ctxt.lcx, sub_ex); let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty; match *ty { ty::TyStruct(def, _) => { diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index e7a3739cb3f..0d4d97d2b6a 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -38,6 +38,7 @@ mod dump_csv; pub struct SaveContext<'l, 'tcx: 'l> { tcx: &'l ty::ctxt<'tcx>, + lcx: &'l lowering::LoweringContext<'tcx>, span_utils: SpanUtils<'l>, } @@ -176,16 +177,18 @@ pub struct MethodCallData { impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { - pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext<'l, 'tcx> { + pub fn new(tcx: &'l ty::ctxt<'tcx>, lcx: &'l lowering::LoweringContext<'tcx>) -> SaveContext<'l, 'tcx> { let span_utils = SpanUtils::new(&tcx.sess); - SaveContext::from_span_utils(tcx, span_utils) + SaveContext::from_span_utils(tcx, lcx, span_utils) } pub fn from_span_utils(tcx: &'l ty::ctxt<'tcx>, + lcx: &'l lowering::LoweringContext<'tcx>, span_utils: SpanUtils<'l>) -> SaveContext<'l, 'tcx> { SaveContext { tcx: tcx, + lcx: lcx, span_utils: span_utils, } } @@ -454,7 +457,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { match expr.node { ast::ExprField(ref sub_ex, ident) => { - let hir_node = lowering::lower_expr(sub_ex); + let hir_node = lowering::lower_expr(self.lcx, sub_ex); let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty; match *ty { ty::TyStruct(def, _) => { @@ -474,7 +477,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } } ast::ExprStruct(ref path, _, _) => { - let hir_node = lowering::lower_expr(expr); + let hir_node = lowering::lower_expr(self.lcx, expr); let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty; match *ty { ty::TyStruct(def, _) => { @@ -705,10 +708,11 @@ impl<'v> Visitor<'v> for PathCollector { } } -pub fn process_crate(tcx: &ty::ctxt, - krate: &ast::Crate, - analysis: &ty::CrateAnalysis, - odir: Option<&Path>) { +pub fn process_crate<'l, 'tcx>(tcx: &'l ty::ctxt<'tcx>, + lcx: &'l lowering::LoweringContext<'tcx>, + krate: &ast::Crate, + analysis: &ty::CrateAnalysis, + odir: Option<&Path>) { if generated_code(krate.span) { return; } @@ -757,7 +761,7 @@ pub fn process_crate(tcx: &ty::ctxt, }; root_path.pop(); - let mut visitor = dump_csv::DumpCsvVisitor::new(tcx, analysis, output_file); + let mut visitor = dump_csv::DumpCsvVisitor::new(tcx, lcx, analysis, output_file); visitor.dump_crate_info(&cratename, krate); visit::walk_crate(&mut visitor, krate);