diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 88c5c38172a..b8d8e6ad0a1 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -543,7 +543,7 @@ fn drop(&mut self) { 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 @@ -1051,7 +1051,7 @@ fn drop(&mut self) { 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. diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index a65d4225a1f..e5c9a818183 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -2048,9 +2048,8 @@ fn float_cast(bcx: Block, } 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); @@ -2080,7 +2079,9 @@ fn float_cast(bcx: Block, } 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(); } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d3cf9ae6dff..d5e3139016f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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); } diff --git a/src/test/compile-fail/cast-rfc0401.rs b/src/test/compile-fail/cast-rfc0401.rs index 3aa866677a8..69ef5421377 100644 --- a/src/test/compile-fail/cast-rfc0401.rs +++ b/src/test/compile-fail/cast-rfc0401.rs @@ -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 diff --git a/src/test/compile-fail/fat-ptr-cast.rs b/src/test/compile-fail/fat-ptr-cast.rs index f6633547a7b..25cab09b7cb 100644 --- a/src/test/compile-fail/fat-ptr-cast.rs +++ b/src/test/compile-fail/fat-ptr-cast.rs @@ -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]; @@ -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 diff --git a/src/test/run-pass/cast-rfc0401.rs b/src/test/run-pass/cast-rfc0401.rs index 92fc2f846ba..ec4c84a1a6b 100644 --- a/src/test/run-pass/cast-rfc0401.rs +++ b/src/test/run-pass/cast-rfc0401.rs @@ -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]; diff --git a/src/test/run-pass/fat-ptr-cast.rs b/src/test/run-pass/fat-ptr-cast.rs index b7513da99c8..91637d111fe 100644 --- a/src/test/run-pass/fat-ptr-cast.rs +++ b/src/test/run-pass/fat-ptr-cast.rs @@ -32,13 +32,12 @@ 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 @@ -46,4 +45,5 @@ fn main() { assert!(b == d); assert!(c == d as usize); + }