1- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+ // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22// file at the top-level directory of this distribution and at
33// http://rust-lang.org/COPYRIGHT.
44//
@@ -39,7 +39,7 @@ use core::prelude::*;
3939use list:: { MutList , MutCons , MutNil } ;
4040
4141use core:: at_vec;
42- use core:: cast:: { transmute, transmute_mut_region} ;
42+ use core:: cast:: { transmute, transmute_mut , transmute_mut_region} ;
4343use core:: cast;
4444use core:: libc:: size_t;
4545use core:: ptr;
@@ -74,6 +74,7 @@ struct Chunk {
7474 is_pod : bool ,
7575}
7676
77+ #[ mutable]
7778pub struct Arena {
7879 // The head is separated out from the list as a unbenchmarked
7980 // microoptimization, to avoid needing to case on the list to
@@ -269,23 +270,22 @@ impl Arena {
269270
270271 // The external interface
271272 #[ inline]
272- pub fn alloc < ' a , T > ( & ' a mut self , op : & fn ( ) -> T ) -> & ' a T {
273+ pub fn alloc < ' a , T > ( & ' a self , op : & fn ( ) -> T ) -> & ' a T {
273274 unsafe {
274275 // XXX: Borrow check
275- let this = transmute_mut_region ( self ) ;
276- if !intrinsics:: needs_drop :: < T > ( ) {
277- return this. alloc_pod ( op) ;
276+ let this = transmute_mut ( self ) ;
277+ if intrinsics:: needs_drop :: < T > ( ) {
278+ this. alloc_nonpod ( op)
279+ } else {
280+ this. alloc_pod ( op)
278281 }
279- // XXX: Borrow check
280- let this = transmute_mut_region ( self ) ;
281- this. alloc_nonpod ( op)
282282 }
283283 }
284284}
285285
286286#[ test]
287287fn test_arena_destructors ( ) {
288- let mut arena = Arena ( ) ;
288+ let arena = Arena ( ) ;
289289 for uint:: range( 0 , 10 ) |i| {
290290 // Arena allocate something with drop glue to make sure it
291291 // doesn't leak.
@@ -300,7 +300,7 @@ fn test_arena_destructors() {
300300#[ should_fail]
301301#[ ignore( cfg( windows) ) ]
302302fn test_arena_destructors_fail( ) {
303- let mut arena = Arena ( ) ;
303+ let arena = Arena ( ) ;
304304 // Put some stuff in the arena.
305305 for uint:: range( 0 , 10 ) |i| {
306306 // Arena allocate something with drop glue to make sure it
0 commit comments