rust/tests/ui/coercion/ptr-mutability-errors.rs
2025-07-05 00:45:24 +05:00

25 lines
1007 B
Rust

//! Tests that pointer coercions preserving mutability are enforced:
//@ dont-require-annotations: NOTE
pub fn main() {
// *const -> *mut
let x: *const isize = &42;
let x: *mut isize = x; //~ ERROR mismatched types
//~| NOTE expected raw pointer `*mut isize`
//~| NOTE found raw pointer `*const isize`
//~| NOTE types differ in mutability
// & -> *mut
let x: *mut isize = &42; //~ ERROR mismatched types
//~| NOTE expected raw pointer `*mut isize`
//~| NOTE found reference `&isize`
//~| NOTE types differ in mutability
let x: *const isize = &42;
let x: *mut isize = x; //~ ERROR mismatched types
//~| NOTE expected raw pointer `*mut isize`
//~| NOTE found raw pointer `*const isize`
//~| NOTE types differ in mutability
}