auto merge of #9088 : nikomatsakis/rust/issue-6304-AST-tree-not-DAG, r=catamorphism

Ensures that each AST node has a unique id. Fixes numerous bugs in macro expansion and deriving. Add two
representative tests.

Fixes #7971
Fixes #6304
Fixes #8367
Fixes #8754
Fixes #8852
Fixes #2543
Fixes #7654
This commit is contained in:
bors
2013-09-10 03:10:59 -07:00
28 changed files with 532 additions and 384 deletions

View File

@@ -12,6 +12,7 @@ use ast::*;
use ast;
use ast_util;
use codemap::{Span, dummy_sp};
use fold;
use opt_vec;
use parse::token;
use visit::{SimpleVisitor, Visitor};
@@ -370,6 +371,21 @@ pub fn empty_generics() -> Generics {
ty_params: opt_vec::Empty}
}
///////////////////////////////////////////////////////////////////////////
// Assigning node ids
fn node_id_assigner(next_id: @fn() -> ast::NodeId) -> @fold::ast_fold {
let precursor = @fold::AstFoldFns {
new_id: |old_id| {
assert_eq!(old_id, ast::DUMMY_NODE_ID);
next_id()
},
..*fold::default_ast_fold()
};
fold::make_fold(precursor)
}
// ______________________________________________________________________
// Enumerating the IDs which appear in an AST