rust/src/test/ui/ptr-coercion.rs

24 lines
981 B
Rust
Raw Normal View History

// Test coercions between pointers which don't do anything fancy like unsizing.
// These are testing that we don't lose mutability when converting to raw pointers.
pub fn main() {
// *const -> *mut
2015-01-31 17:23:42 +01:00
let x: *const isize = &42;
2015-01-12 01:01:44 -05:00
let x: *mut isize = x; //~ ERROR mismatched types
//~| expected type `*mut isize`
//~| found type `*const isize`
2016-08-19 16:05:37 -07:00
//~| types differ in mutability
// & -> *mut
2015-01-12 01:01:44 -05:00
let x: *mut isize = &42; //~ ERROR mismatched types
//~| expected type `*mut isize`
//~| found type `&isize`
2016-08-19 16:05:37 -07:00
//~| types differ in mutability
let x: *const isize = &42;
2015-01-12 01:01:44 -05:00
let x: *mut isize = x; //~ ERROR mismatched types
//~| expected type `*mut isize`
//~| found type `*const isize`
2016-08-19 16:05:37 -07:00
//~| types differ in mutability
}