about summary refs log tree commit diff
path: root/tests/ui/coercion/ptr-mutability-errors.rs
blob: 391eaf0b91343f1b2fce92e2dfef98e3bc0943bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! 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
}