1
Fork 0

rustc_passes: fix compilation

This commit is contained in:
Florian Diebold 2016-10-29 15:01:11 +02:00 committed by Florian Diebold
parent 37e75411dd
commit 0389cc6bcd
5 changed files with 50 additions and 32 deletions

View file

@ -48,7 +48,7 @@ use rustc::lint::builtin::CONST_ERR;
use rustc::hir::{self, PatKind}; use rustc::hir::{self, PatKind};
use syntax::ast; use syntax::ast;
use syntax_pos::Span; 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::collections::hash_map::Entry;
use std::cmp::Ordering; use std::cmp::Ordering;
@ -100,7 +100,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
.enter(|infcx| f(&mut euv::ExprUseVisitor::new(self, &infcx))) .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); assert!(mode != Mode::Var);
match self.tcx.const_qualif_map.borrow_mut().entry(expr.id) { match self.tcx.const_qualif_map.borrow_mut().entry(expr.id) {
Entry::Occupied(entry) => return *entry.get(), Entry::Occupied(entry) => return *entry.get(),
@ -132,9 +132,9 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
} }
fn fn_like(&mut self, fn fn_like(&mut self,
fk: FnKind, fk: FnKind<'gcx>,
fd: &hir::FnDecl, fd: &'gcx hir::FnDecl,
b: &hir::Expr, b: hir::ExprId,
s: Span, s: Span,
fn_id: ast::NodeId) fn_id: ast::NodeId)
-> ConstQualif { -> ConstQualif {
@ -160,7 +160,8 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
}; };
let qualif = self.with_mode(mode, |this| { 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); intravisit::walk_fn(this, fk, fd, b, s, fn_id);
this.qualif this.qualif
}); });
@ -213,8 +214,12 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
} }
} }
impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
fn visit_item(&mut self, i: &hir::Item) { 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)); debug!("visit_item(item={})", self.tcx.map.node_to_string(i.id));
assert_eq!(self.mode, Mode::Var); assert_eq!(self.mode, Mode::Var);
match i.node { match i.node {
@ -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 { match t.node {
hir::ConstTraitItem(_, ref default) => { hir::ConstTraitItem(_, ref default) => {
if let Some(ref expr) = *default { if let Some(ref expr) = *default {
@ -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 { match i.node {
hir::ImplItemKind::Const(_, ref expr) => { hir::ImplItemKind::Const(_, ref expr) => {
self.global_expr(Mode::Const, &expr); self.global_expr(Mode::Const, &expr);
@ -263,15 +268,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
} }
fn visit_fn(&mut self, fn visit_fn(&mut self,
fk: FnKind<'v>, fk: FnKind<'tcx>,
fd: &'v hir::FnDecl, fd: &'tcx hir::FnDecl,
b: &'v hir::Expr, b: hir::ExprId,
s: Span, s: Span,
fn_id: ast::NodeId) { fn_id: ast::NodeId) {
self.fn_like(fk, fd, b, s, fn_id); 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 { match p.node {
PatKind::Lit(ref lit) => { PatKind::Lit(ref lit) => {
self.global_expr(Mode::Const, &lit); self.global_expr(Mode::Const, &lit);
@ -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 // Check all statements in the block
for stmt in &block.stmts { for stmt in &block.stmts {
match stmt.node { match stmt.node {
@ -315,7 +320,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
intravisit::walk_block(self, block); 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; let mut outer = self.qualif;
self.qualif = ConstQualif::empty(); self.qualif = ConstQualif::empty();

View file

@ -106,7 +106,7 @@ impl<'k> StatCollector<'k> {
} }
impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { 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") panic!("visit_nested_xxx must be manually implemented in this visitor")
} }
@ -172,7 +172,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
fn visit_fn(&mut self, fn visit_fn(&mut self,
fk: hir_visit::FnKind<'v>, fk: hir_visit::FnKind<'v>,
fd: &'v hir::FnDecl, fd: &'v hir::FnDecl,
b: &'v hir::Expr, b: hir::ExprId,
s: Span, s: Span,
id: NodeId) { id: NodeId) {
self.record("FnDecl", Id::None, fd); self.record("FnDecl", Id::None, fd);

View file

@ -13,7 +13,7 @@ use rustc::session::Session;
use rustc::dep_graph::DepNode; use rustc::dep_graph::DepNode;
use rustc::hir::map::Map; use rustc::hir::map::Map;
use rustc::hir::intravisit::{self, Visitor}; use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
use rustc::hir; use rustc::hir;
use syntax::ast; use syntax::ast;
use syntax_pos::Span; use syntax_pos::Span;
@ -59,16 +59,20 @@ pub fn check_crate(sess: &Session, map: &Map) {
}.as_deep_visitor()); }.as_deep_visitor());
} }
impl<'a, 'ast, 'v> Visitor<'v> for CheckLoopVisitor<'a, 'ast> { impl<'a, 'ast> Visitor<'ast> for CheckLoopVisitor<'a, 'ast> {
fn visit_item(&mut self, i: &hir::Item) { 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)); 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)); 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 { match e.node {
hir::ExprWhile(ref e, ref b, _) => { hir::ExprWhile(ref e, ref b, _) => {
self.with_context(Loop(LoopKind::WhileLoop), |v| { self.with_context(Loop(LoopKind::WhileLoop), |v| {
@ -79,8 +83,8 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckLoopVisitor<'a, 'ast> {
hir::ExprLoop(ref b, _, source) => { hir::ExprLoop(ref b, _, source) => {
self.with_context(Loop(LoopKind::Loop(source)), |v| v.visit_block(&b)); self.with_context(Loop(LoopKind::Loop(source)), |v| v.visit_block(&b));
} }
hir::ExprClosure(.., ref b, _) => { hir::ExprClosure(.., b, _) => {
self.with_context(Closure, |v| v.visit_expr(&b)); self.with_context(Closure, |v| v.visit_body(b));
} }
hir::ExprBreak(label, ref opt_expr) => { hir::ExprBreak(label, ref opt_expr) => {
if opt_expr.is_some() { if opt_expr.is_some() {

View file

@ -18,7 +18,7 @@ use rustc::ty::{self, TyCtxt, ParameterEnvironment};
use rustc::traits::Reveal; use rustc::traits::Reveal;
use rustc::hir; use rustc::hir;
use rustc::hir::intravisit::{self, Visitor}; use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
use syntax::ast; use syntax::ast;
use syntax_pos::Span; use syntax_pos::Span;
@ -31,11 +31,15 @@ struct RvalueContext<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>, 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, fn visit_fn(&mut self,
fk: intravisit::FnKind<'v>, fk: intravisit::FnKind<'tcx>,
fd: &'v hir::FnDecl, fd: &'tcx hir::FnDecl,
b: &'v hir::Expr, b: hir::ExprId,
s: Span, s: Span,
fn_id: ast::NodeId) { fn_id: ast::NodeId) {
// FIXME (@jroesch) change this to be an inference context // FIXME (@jroesch) change this to be an inference context
@ -46,8 +50,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for RvalueContext<'a, 'tcx> {
tcx: infcx.tcx, tcx: infcx.tcx,
param_env: &param_env param_env: &param_env
}; };
let body = infcx.tcx.map.expr(b);
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx); 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) intravisit::walk_fn(self, fk, fd, b, s, fn_id)
} }

View file

@ -20,7 +20,7 @@ use rustc::util::nodemap::NodeMap;
use syntax::ast; use syntax::ast;
use syntax::feature_gate::{GateIssue, emit_feature_err}; use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax_pos::Span; use syntax_pos::Span;
use rustc::hir::intravisit::{self, Visitor}; use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
use rustc::hir; use rustc::hir;
use std::cell::RefCell; use std::cell::RefCell;
@ -200,6 +200,10 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
} }
impl<'a, 'ast: 'a> Visitor<'ast> for 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) { fn visit_item(&mut self, it: &'ast hir::Item) {
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it), it.span); self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it), it.span);
} }