Skip to content

return &mut T from the arenas, not &T #18407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ impl Arena {
}

#[inline]
fn alloc_copy<T>(&self, op: || -> T) -> &T {
fn alloc_copy<T>(&self, op: || -> T) -> &mut T {
unsafe {
let ptr = self.alloc_copy_inner(mem::size_of::<T>(),
mem::min_align_of::<T>());
let ptr = ptr as *mut T;
ptr::write(&mut (*ptr), op());
return &*ptr;
return &mut *ptr;
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ impl Arena {
}

#[inline]
fn alloc_noncopy<T>(&self, op: || -> T) -> &T {
fn alloc_noncopy<T>(&self, op: || -> T) -> &mut T {
unsafe {
let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) =
Expand All @@ -279,14 +279,14 @@ impl Arena {
// the object is there.
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);

return &*ptr;
return &mut *ptr;
}
}

/// Allocates a new item in the arena, using `op` to initialize the value,
/// and returns a reference to it.
#[inline]
pub fn alloc<T>(&self, op: || -> T) -> &T {
pub fn alloc<T>(&self, op: || -> T) -> &mut T {
unsafe {
if intrinsics::needs_drop::<T>() {
self.alloc_noncopy(op)
Expand Down Expand Up @@ -459,12 +459,12 @@ impl<T> TypedArena<T> {

/// Allocates an object in the `TypedArena`, returning a reference to it.
#[inline]
pub fn alloc(&self, object: T) -> &T {
pub fn alloc(&self, object: T) -> &mut T {
if self.ptr == self.end {
self.grow()
}

let ptr: &T = unsafe {
let ptr: &mut T = unsafe {
let ptr: &mut T = mem::transmute(self.ptr);
ptr::write(ptr, object);
self.ptr.set(self.ptr.get().offset(1));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
}

_ => {
self.terms_cx.arena.alloc(|| TransformTerm(v1, v2))
&*self.terms_cx.arena.alloc(|| TransformTerm(v1, v2))
}
}
}
Expand Down