Skip to content

Commit

Permalink
rustc_passes: fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
flodiebold committed Nov 29, 2016
1 parent 37e7541 commit 0389cc6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
37 changes: 21 additions & 16 deletions src/librustc_passes/consts.rs
Expand Up @@ -48,7 +48,7 @@ use rustc::lint::builtin::CONST_ERR;
use rustc::hir::{self, PatKind};
use syntax::ast;
use syntax_pos::Span;
use rustc::hir::intravisit::{self, FnKind, Visitor};
use rustc::hir::intravisit::{self, FnKind, Visitor, NestedVisitMode};

use std::collections::hash_map::Entry;
use std::cmp::Ordering;
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
.enter(|infcx| f(&mut euv::ExprUseVisitor::new(self, &infcx)))
}

fn global_expr(&mut self, mode: Mode, expr: &hir::Expr) -> ConstQualif {
fn global_expr(&mut self, mode: Mode, expr: &'gcx hir::Expr) -> ConstQualif {
assert!(mode != Mode::Var);
match self.tcx.const_qualif_map.borrow_mut().entry(expr.id) {
Entry::Occupied(entry) => return *entry.get(),
Expand Down Expand Up @@ -132,9 +132,9 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
}

fn fn_like(&mut self,
fk: FnKind,
fd: &hir::FnDecl,
b: &hir::Expr,
fk: FnKind<'gcx>,
fd: &'gcx hir::FnDecl,
b: hir::ExprId,
s: Span,
fn_id: ast::NodeId)
-> ConstQualif {
Expand All @@ -160,7 +160,8 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
};

let qualif = self.with_mode(mode, |this| {
this.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b));
let body = this.tcx.map.expr(b);
this.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, body));
intravisit::walk_fn(this, fk, fd, b, s, fn_id);
this.qualif
});
Expand Down Expand Up @@ -213,8 +214,12 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
}
}

impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
fn visit_item(&mut self, i: &hir::Item) {
impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
}

fn visit_item(&mut self, i: &'tcx hir::Item) {
debug!("visit_item(item={})", self.tcx.map.node_to_string(i.id));
assert_eq!(self.mode, Mode::Var);
match i.node {
Expand All @@ -240,7 +245,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
}
}

fn visit_trait_item(&mut self, t: &'v hir::TraitItem) {
fn visit_trait_item(&mut self, t: &'tcx hir::TraitItem) {
match t.node {
hir::ConstTraitItem(_, ref default) => {
if let Some(ref expr) = *default {
Expand All @@ -253,7 +258,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
}
}

fn visit_impl_item(&mut self, i: &'v hir::ImplItem) {
fn visit_impl_item(&mut self, i: &'tcx hir::ImplItem) {
match i.node {
hir::ImplItemKind::Const(_, ref expr) => {
self.global_expr(Mode::Const, &expr);
Expand All @@ -263,15 +268,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
}

fn visit_fn(&mut self,
fk: FnKind<'v>,
fd: &'v hir::FnDecl,
b: &'v hir::Expr,
fk: FnKind<'tcx>,
fd: &'tcx hir::FnDecl,
b: hir::ExprId,
s: Span,
fn_id: ast::NodeId) {
self.fn_like(fk, fd, b, s, fn_id);
}

fn visit_pat(&mut self, p: &hir::Pat) {
fn visit_pat(&mut self, p: &'tcx hir::Pat) {
match p.node {
PatKind::Lit(ref lit) => {
self.global_expr(Mode::Const, &lit);
Expand All @@ -296,7 +301,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
}
}

fn visit_block(&mut self, block: &hir::Block) {
fn visit_block(&mut self, block: &'tcx hir::Block) {
// Check all statements in the block
for stmt in &block.stmts {
match stmt.node {
Expand All @@ -315,7 +320,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
intravisit::walk_block(self, block);
}

fn visit_expr(&mut self, ex: &hir::Expr) {
fn visit_expr(&mut self, ex: &'tcx hir::Expr) {
let mut outer = self.qualif;
self.qualif = ConstQualif::empty();

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/hir_stats.rs
Expand Up @@ -106,7 +106,7 @@ impl<'k> StatCollector<'k> {
}

impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'v>> {
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'v>, hir_visit::NestedVisitMode)> {
panic!("visit_nested_xxx must be manually implemented in this visitor")
}

Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
fn visit_fn(&mut self,
fk: hir_visit::FnKind<'v>,
fd: &'v hir::FnDecl,
b: &'v hir::Expr,
b: hir::ExprId,
s: Span,
id: NodeId) {
self.record("FnDecl", Id::None, fd);
Expand Down
18 changes: 11 additions & 7 deletions src/librustc_passes/loops.rs
Expand Up @@ -13,7 +13,7 @@ use rustc::session::Session;

use rustc::dep_graph::DepNode;
use rustc::hir::map::Map;
use rustc::hir::intravisit::{self, Visitor};
use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
use rustc::hir;
use syntax::ast;
use syntax_pos::Span;
Expand Down Expand Up @@ -59,16 +59,20 @@ pub fn check_crate(sess: &Session, map: &Map) {
}.as_deep_visitor());
}

impl<'a, 'ast, 'v> Visitor<'v> for CheckLoopVisitor<'a, 'ast> {
fn visit_item(&mut self, i: &hir::Item) {
impl<'a, 'ast> Visitor<'ast> for CheckLoopVisitor<'a, 'ast> {
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'ast>, NestedVisitMode)> {
Some((&self.hir_map, NestedVisitMode::OnlyBodies))
}

fn visit_item(&mut self, i: &'ast hir::Item) {
self.with_context(Normal, |v| intravisit::walk_item(v, i));
}

fn visit_impl_item(&mut self, i: &hir::ImplItem) {
fn visit_impl_item(&mut self, i: &'ast hir::ImplItem) {
self.with_context(Normal, |v| intravisit::walk_impl_item(v, i));
}

fn visit_expr(&mut self, e: &hir::Expr) {
fn visit_expr(&mut self, e: &'ast hir::Expr) {
match e.node {
hir::ExprWhile(ref e, ref b, _) => {
self.with_context(Loop(LoopKind::WhileLoop), |v| {
Expand All @@ -79,8 +83,8 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckLoopVisitor<'a, 'ast> {
hir::ExprLoop(ref b, _, source) => {
self.with_context(Loop(LoopKind::Loop(source)), |v| v.visit_block(&b));
}
hir::ExprClosure(.., ref b, _) => {
self.with_context(Closure, |v| v.visit_expr(&b));
hir::ExprClosure(.., b, _) => {
self.with_context(Closure, |v| v.visit_body(b));
}
hir::ExprBreak(label, ref opt_expr) => {
if opt_expr.is_some() {
Expand Down
17 changes: 11 additions & 6 deletions src/librustc_passes/rvalues.rs
Expand Up @@ -18,7 +18,7 @@ use rustc::ty::{self, TyCtxt, ParameterEnvironment};
use rustc::traits::Reveal;

use rustc::hir;
use rustc::hir::intravisit::{self, Visitor};
use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
use syntax::ast;
use syntax_pos::Span;

Expand All @@ -31,11 +31,15 @@ struct RvalueContext<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

impl<'a, 'tcx, 'v> Visitor<'v> for RvalueContext<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for RvalueContext<'a, 'tcx> {
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
}

fn visit_fn(&mut self,
fk: intravisit::FnKind<'v>,
fd: &'v hir::FnDecl,
b: &'v hir::Expr,
fk: intravisit::FnKind<'tcx>,
fd: &'tcx hir::FnDecl,
b: hir::ExprId,
s: Span,
fn_id: ast::NodeId) {
// FIXME (@jroesch) change this to be an inference context
Expand All @@ -46,8 +50,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for RvalueContext<'a, 'tcx> {
tcx: infcx.tcx,
param_env: &param_env
};
let body = infcx.tcx.map.expr(b);
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx);
euv.walk_fn(fd, b);
euv.walk_fn(fd, body);
});
intravisit::walk_fn(self, fk, fd, b, s, fn_id)
}
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_passes/static_recursion.rs
Expand Up @@ -20,7 +20,7 @@ use rustc::util::nodemap::NodeMap;
use syntax::ast;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax_pos::Span;
use rustc::hir::intravisit::{self, Visitor};
use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
use rustc::hir;

use std::cell::RefCell;
Expand Down Expand Up @@ -200,6 +200,10 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
}

impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'ast>, NestedVisitMode)> {
Some((&self.ast_map, NestedVisitMode::OnlyBodies))
}

fn visit_item(&mut self, it: &'ast hir::Item) {
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it), it.span);
}
Expand Down

0 comments on commit 0389cc6

Please sign in to comment.