Skip to content

Commit 7fd23e4

Browse files
committed
Convert uses of transmute which don't need it
1 parent 467d381 commit 7fd23e4

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/libstd/cleanup.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use libc::c_void;
1414
use ptr::{mut_null};
1515
use repr::BoxRepr;
16-
use cast::transmute;
1716
use unstable::intrinsics::TyDesc;
1817

1918
type DropGlue<'self> = &'self fn(**TyDesc, *c_void);
@@ -40,18 +39,17 @@ unsafe fn each_live_alloc(read_next_before: bool,
4039
let box = local_heap::live_allocs();
4140
let mut box: *mut BoxRepr = transmute(box);
4241
while box != mut_null() {
43-
let next_before = transmute((*box).header.next);
44-
let uniq =
45-
(*box).header.ref_count == managed::raw::RC_MANAGED_UNIQUE;
42+
let next_before = (*box).next;
43+
let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE;
4644

47-
if !f(box, uniq) {
45+
if !f(box as *mut raw::Box<()>, uniq) {
4846
return false;
4947
}
5048

5149
if read_next_before {
5250
box = next_before;
5351
} else {
54-
box = transmute((*box).header.next);
52+
box = (*box).next;
5553
}
5654
}
5755
return true;
@@ -113,9 +111,9 @@ pub unsafe fn annihilate() {
113111
// callback, as the original value may have been freed.
114112
for each_live_alloc(false) |box, uniq| {
115113
if !uniq {
116-
let tydesc: *TyDesc = transmute((*box).header.type_desc);
117-
let data = transmute(&(*box).data);
118-
((*tydesc).drop_glue)(data);
114+
let tydesc = (*box).type_desc;
115+
let data = &(*box).data as *();
116+
((*tydesc).drop_glue)(data as *i8);
119117
}
120118
}
121119

@@ -130,7 +128,7 @@ pub unsafe fn annihilate() {
130128
stats.n_bytes_freed +=
131129
(*((*box).header.type_desc)).size
132130
+ sys::size_of::<BoxRepr>();
133-
local_free(transmute(box));
131+
local_free(box as *u8);
134132
}
135133
}
136134

src/libstd/gc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ pub mod rustrt {
7474
}
7575

7676
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
77-
return cast::transmute(ptr::offset(ptr, count));
77+
return ptr::offset(ptr, count) as *U;
7878
}
7979

8080
unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
8181
let align = sys::min_align_of::<*T>();
82-
let ptr: uint = cast::transmute(ptr);
82+
let ptr = ptr as uint;
8383
let ptr = (ptr + (align - 1)) & -align;
84-
return cast::transmute(ptr);
84+
return ptr as *T;
8585
}
8686

8787
unsafe fn get_safe_point_count() -> uint {
@@ -126,8 +126,8 @@ type Visitor<'self> = &'self fn(root: **Word, tydesc: *TyDesc) -> bool;
126126
// Walks the list of roots for the given safe point, and calls visitor
127127
// on each root.
128128
unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
129-
let fp_bytes: *u8 = cast::transmute(fp);
130-
let sp_meta: *u32 = cast::transmute(sp.sp_meta);
129+
let fp_bytes = fp as *u8;
130+
let sp_meta = sp.sp_meta as *u32;
131131

132132
let num_stack_roots = *sp_meta as uint;
133133
let num_reg_roots = *ptr::offset(sp_meta, 1) as uint;
@@ -173,9 +173,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
173173

174174
// Is fp contained in segment?
175175
unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
176-
let begin: Word = cast::transmute(segment);
177-
let end: Word = cast::transmute((*segment).end);
178-
let frame: Word = cast::transmute(fp);
176+
let begin = segment as Word;
177+
let end = (*segment).end as Word;
178+
let frame = fp as Word;
179179

180180
return begin <= frame && frame <= end;
181181
}

0 commit comments

Comments
 (0)