Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed May 19, 2015
1 parent 9ee2335 commit d9b9f4e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/rc.rs
Expand Up @@ -543,7 +543,7 @@ impl<T: ?Sized> Drop for Rc<T> {
unsafe {
let ptr = *self._ptr;
if !(*(&ptr as *const _ as *const *const ())).is_null() &&
ptr as usize != mem::POST_DROP_USIZE {
ptr as *const () as usize != mem::POST_DROP_USIZE {
self.dec_strong();
if self.strong() == 0 {
// destroy the contained object
Expand Down Expand Up @@ -1051,7 +1051,7 @@ impl<T: ?Sized> Drop for Weak<T> {
unsafe {
let ptr = *self._ptr;
if !(*(&ptr as *const _ as *const *const ())).is_null() &&
ptr as usize != mem::POST_DROP_USIZE {
ptr as *const () as usize != mem::POST_DROP_USIZE {
self.dec_weak();
// the weak count starts at 1, and will only go to zero if all
// the strong pointers have disappeared.
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_trans/trans/expr.rs
Expand Up @@ -2048,9 +2048,8 @@ fn trans_imm_cast<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} else { llsrc };
}

let _icx = push_ctxt("trans_cast");
let mut bcx = bcx;
let ccx = bcx.ccx();
let _icx = push_ctxt("trans_cast"); let mut bcx = bcx; let ccx =
bcx.ccx();

let t_in = expr_ty_adjusted(bcx, expr);
let t_out = node_id_type(bcx, id);
Expand Down Expand Up @@ -2080,7 +2079,9 @@ fn trans_imm_cast<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} else {
// Return the address
return immediate_rvalue_bcx(bcx,
Load(bcx, get_dataptr(bcx, datum.val)),
PointerCast(bcx,
Load(bcx, get_dataptr(bcx, datum.val)),
ll_t_out),
t_out).to_expr_datumblock();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -528,6 +528,9 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
upvar::closure_analyze_fn(&fcx, fn_id, decl, body);
fcx.select_all_obligations_or_error();
fcx.check_casts();

fcx.select_all_obligations_or_error(); // Casts can introduce new obligations.

regionck::regionck_fn(&fcx, fn_id, fn_span, decl, body);
writeback::resolve_type_vars_in_fn(&fcx, decl, body);
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/cast-rfc0401.rs
Expand Up @@ -56,7 +56,8 @@ fn main()

let _ = 42usize as *const [u8]; //~ ERROR illegal cast
let _ = v as *const [u8]; //~ ERROR illegal cast
let _ = fat_v as *const Foo; //~ ERROR illegal cast
let _ = fat_v as *const Foo;
//~^ ERROR `core::marker::Sized` is not implemented for the type `[u8]`
let _ = foo as *const str; //~ ERROR illegal cast
let _ = foo as *mut str; //~ ERROR illegal cast
let _ = main as *mut str; //~ ERROR illegal cast
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/fat-ptr-cast.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

trait Trait {}

// Make sure casts between thin-pointer <-> fat pointer obey RFC401
fn main() {
let a: &[i32] = &[1, 2, 3];
Expand All @@ -17,7 +19,7 @@ fn main() {

a as usize; //~ ERROR illegal cast
b as usize; //~ ERROR non-scalar cast
p as usize; //~ ERROR illegal cast
p as usize; //~ ERROR illegal cast; cast through a raw pointer

// #22955
q as *const [i32]; //~ ERROR illegal cast
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-pass/cast-rfc0401.rs
Expand Up @@ -85,7 +85,9 @@ fn main()
assert_eq!(w as usize, lsz);

// ptr-ptr-cast (fat->thin)
let u: *const [u8] = unsafe{&*p}; assert_eq!(u as *const u8, p as *const u8);
let u: *const [u8] = unsafe{&*p};
assert_eq!(u as *const u8, p as *const u8);
assert_eq!(u as *const u16, p as *const u16);

// ptr-ptr-cast (both vk=Length)
let mut l : [u8; 2] = [0,1];
Expand Down
6 changes: 3 additions & 3 deletions src/test/run-pass/fat-ptr-cast.rs
Expand Up @@ -32,18 +32,18 @@ fn main() {
// Test conversion to an address (usize).
let a: *const [i32; 3] = &[1, 2, 3];
let b: *const [i32] = a;
assert!(a as usize == b as usize);
assert!(a as usize == b as *const () as usize);

// And conversion to a void pointer/address for trait objects too.
let a: *mut Foo = &mut Bar;
let b = a as *mut ();
let c = a as usize;

let c = a as *const () as usize;
let d = unsafe {
let r: raw::TraitObject = mem::transmute(a);
r.data
};

assert!(b == d);
assert!(c == d as usize);

}

0 comments on commit d9b9f4e

Please sign in to comment.