提交 5001c92c 编写于 作者: N Niko Matsakis

stop hashing nested items, and add a test

上级 775bd93d
...@@ -182,7 +182,6 @@ enum SawAbiComponent<'a> { ...@@ -182,7 +182,6 @@ enum SawAbiComponent<'a> {
SawMod, SawMod,
SawForeignItem, SawForeignItem,
SawItem, SawItem,
SawDecl,
SawTy, SawTy,
SawGenerics, SawGenerics,
SawFn, SawFn,
...@@ -285,24 +284,13 @@ fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> { ...@@ -285,24 +284,13 @@ fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> {
/// SawStmtComponent is analogous to SawExprComponent, but for statements. /// SawStmtComponent is analogous to SawExprComponent, but for statements.
#[derive(Hash)] #[derive(Hash)]
pub enum SawStmtComponent { pub enum SawStmtComponent {
SawStmtDecl,
SawStmtExpr, SawStmtExpr,
SawStmtSemi, SawStmtSemi,
} }
fn saw_stmt(node: &Stmt_) -> SawStmtComponent {
match *node {
StmtDecl(..) => SawStmtDecl,
StmtExpr(..) => SawStmtExpr,
StmtSemi(..) => SawStmtSemi,
}
}
impl<'a, 'tcx> Visitor<'a> for StrictVersionHashVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'a> for StrictVersionHashVisitor<'a, 'tcx> {
fn visit_nested_item(&mut self, item: ItemId) { fn visit_nested_item(&mut self, _: ItemId) {
let def_path = self.tcx.map.def_path_from_id(item.id).unwrap(); // Each item is hashed independently; ignore nested items.
debug!("visit_nested_item: def_path={:?} st={:?}", def_path, self.st);
self.hash_def_path(&def_path);
} }
fn visit_variant_data(&mut self, s: &'a VariantData, name: Name, fn visit_variant_data(&mut self, s: &'a VariantData, name: Name,
...@@ -362,7 +350,20 @@ fn visit_expr(&mut self, ex: &'a Expr) { ...@@ -362,7 +350,20 @@ fn visit_expr(&mut self, ex: &'a Expr) {
fn visit_stmt(&mut self, s: &'a Stmt) { fn visit_stmt(&mut self, s: &'a Stmt) {
debug!("visit_stmt: st={:?}", self.st); debug!("visit_stmt: st={:?}", self.st);
SawStmt(saw_stmt(&s.node)).hash(self.st); visit::walk_stmt(self, s)
// We don't want to modify the hash for decls, because
// they might be item decls (if they are local decls,
// we'll hash that fact in visit_local); but we do want to
// remember if this was a StmtExpr or StmtSemi (the later
// had an explicit semi-colon; this affects the typing
// rules).
match s.node {
StmtDecl(..) => (),
StmtExpr(..) => SawStmt(SawStmtExpr).hash(self.st),
StmtSemi(..) => SawStmt(SawStmtSemi).hash(self.st),
}
visit::walk_stmt(self, s)
} }
fn visit_foreign_item(&mut self, i: &'a ForeignItem) { fn visit_foreign_item(&mut self, i: &'a ForeignItem) {
...@@ -390,11 +391,6 @@ fn visit_mod(&mut self, m: &'a Mod, _s: Span, n: NodeId) { ...@@ -390,11 +391,6 @@ fn visit_mod(&mut self, m: &'a Mod, _s: Span, n: NodeId) {
SawMod.hash(self.st); visit::walk_mod(self, m, n) SawMod.hash(self.st); visit::walk_mod(self, m, n)
} }
fn visit_decl(&mut self, d: &'a Decl) {
debug!("visit_decl: st={:?}", self.st);
SawDecl.hash(self.st); visit::walk_decl(self, d)
}
fn visit_ty(&mut self, t: &'a Ty) { fn visit_ty(&mut self, t: &'a Ty) {
debug!("visit_ty: st={:?}", self.st); debug!("visit_ty: st={:?}", self.st);
SawTy.hash(self.st); visit::walk_ty(self, t) SawTy.hash(self.st); visit::walk_ty(self, t)
......
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Check that the hash of `foo` doesn't change just because we ordered
// the nested items (or even added new ones).
// revisions: rpass1 rpass2
#![feature(rustc_attrs)]
#[cfg(rpass1)]
fn foo() {
fn bar() { }
fn baz() { }
}
#[cfg(rpass2)]
#[rustc_clean(label="Hir", cfg="rpass2")]
fn foo() {
#[rustc_clean(label="Hir", cfg="rpass2")]
fn baz() { } // order is different...
#[rustc_clean(label="Hir", cfg="rpass2")]
fn bar() { } // but that doesn't matter.
fn bap() { } // neither does adding a new item
}
fn main() { }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册