]> git.lizzy.rs Git - rust.git/blob - src/test/ui/vector-cast-weirdness.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / vector-cast-weirdness.rs
1 // Copyright 2012 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 // Issue #14893. Tests that casts from vectors don't behave strangely in the
12 // presence of the `_` type shorthand notation.
13 // Update: after a change to the way casts are done, we have more type information
14 // around and so the errors here are no longer exactly the same.
15
16 struct X {
17     y: [u8; 2],
18 }
19
20 fn main() {
21     let x1 = X { y: [0, 0] };
22
23     // No longer a type mismatch - the `_` can be fully resolved by type inference.
24     let p1: *const u8 = &x1.y as *const _;
25     let t1: *const [u8; 2] = &x1.y as *const _;
26     let h1: *const [u8; 2] = &x1.y as *const [u8; 2];
27
28     let mut x1 = X { y: [0, 0] };
29
30     // This is still an error since we don't allow casts from &mut [T; n] to *mut T.
31     let p1: *mut u8 = &mut x1.y as *mut _;  //~ ERROR casting
32     let t1: *mut [u8; 2] = &mut x1.y as *mut _;
33     let h1: *mut [u8; 2] = &mut x1.y as *mut [u8; 2];
34 }