Files
rust/tests/ui/coercion/ptr-mutability-errors.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
1007 B
Rust
Raw Normal View History

2025-07-01 18:24:12 +05:00
//! Tests that pointer coercions preserving mutability are enforced:
//@ dont-require-annotations: NOTE
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
//~| NOTE expected raw pointer `*mut isize`
//~| NOTE found raw pointer `*const isize`
//~| NOTE types differ in mutability
// & -> *mut
2015-01-12 01:01:44 -05:00
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;
2015-01-12 01:01:44 -05:00
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
}