Skip to content

Commit e4a678d

Browse files
committed
Ported regions-mock-tcx to use TypedArena rather than Arena since it holds
cyclic structure (which the Arena API updated for dropck cannot handle).
1 parent 189930f commit e4a678d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/test/run-pass/regions-mock-tcx.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern crate libc;
2121

2222
use TypeStructure::{TypeInt, TypeFunction};
2323
use AstKind::{ExprInt, ExprVar, ExprLambda};
24-
use arena::Arena;
24+
use arena::TypedArena;
2525
use std::collections::HashMap;
2626
use std::mem;
2727

@@ -45,17 +45,20 @@ impl<'tcx> PartialEq for TypeStructure<'tcx> {
4545

4646
impl<'tcx> Eq for TypeStructure<'tcx> {}
4747

48+
type TyArena<'tcx> = TypedArena<TypeStructure<'tcx>>;
49+
type AstArena<'ast> = TypedArena<AstStructure<'ast>>;
50+
4851
struct TypeContext<'tcx, 'ast> {
49-
ty_arena: &'tcx Arena,
52+
ty_arena: &'tcx TyArena<'tcx>,
5053
types: Vec<Type<'tcx>> ,
5154
type_table: HashMap<NodeId, Type<'tcx>>,
5255

53-
ast_arena: &'ast Arena,
56+
ast_arena: &'ast AstArena<'ast>,
5457
ast_counter: uint,
5558
}
5659

5760
impl<'tcx,'ast> TypeContext<'tcx, 'ast> {
58-
fn new(ty_arena: &'tcx Arena, ast_arena: &'ast Arena)
61+
fn new(ty_arena: &'tcx TyArena<'tcx>, ast_arena: &'ast AstArena<'ast>)
5962
-> TypeContext<'tcx, 'ast> {
6063
TypeContext { ty_arena: ty_arena,
6164
types: Vec::new(),
@@ -72,7 +75,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> {
7275
}
7376
}
7477

75-
let ty = self.ty_arena.alloc(|| s);
78+
let ty = self.ty_arena.alloc(s);
7679
self.types.push(ty);
7780
ty
7881
}
@@ -85,7 +88,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> {
8588
fn ast(&mut self, a: AstKind<'ast>) -> Ast<'ast> {
8689
let id = self.ast_counter;
8790
self.ast_counter += 1;
88-
self.ast_arena.alloc(|| AstStructure { id: NodeId {id:id}, kind: a })
91+
self.ast_arena.alloc(AstStructure { id: NodeId {id:id}, kind: a })
8992
}
9093
}
9194

@@ -127,8 +130,8 @@ fn compute_types<'tcx,'ast>(tcx: &mut TypeContext<'tcx,'ast>,
127130
}
128131

129132
pub fn main() {
130-
let ty_arena = arena::Arena::new();
131-
let ast_arena = arena::Arena::new();
133+
let ty_arena = TypedArena::new();
134+
let ast_arena = TypedArena::new();
132135
let mut tcx = TypeContext::new(&ty_arena, &ast_arena);
133136
let ast = tcx.ast(ExprInt);
134137
let ty = compute_types(&mut tcx, ast);

0 commit comments

Comments
 (0)