]> git.lizzy.rs Git - rust.git/blob - src/test/ui/ptr-coercion.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[rust.git] / src / test / ui / ptr-coercion.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test coercions between pointers which don't do anything fancy like unsizing.
12 // These are testing that we don't lose mutability when converting to raw pointers.
13
14 pub fn main() {
15     // *const -> *mut
16     let x: *const isize = &42;
17     let x: *mut isize = x; //~  ERROR mismatched types
18                            //~| expected type `*mut isize`
19                            //~| found type `*const isize`
20                            //~| types differ in mutability
21
22     // & -> *mut
23     let x: *mut isize = &42; //~  ERROR mismatched types
24                              //~| expected type `*mut isize`
25                              //~| found type `&isize`
26                              //~| types differ in mutability
27
28     let x: *const isize = &42;
29     let x: *mut isize = x; //~  ERROR mismatched types
30                            //~| expected type `*mut isize`
31                            //~| found type `*const isize`
32                            //~| types differ in mutability
33 }