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
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.
} 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);
} 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();
}
}
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);
}
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
// 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];
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
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];
// 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);
+
}