]> git.lizzy.rs Git - rust.git/blob - src/test/ui/transmute/transmute-different-sizes.rs
Rollup merge of #103989 - arlosi:arm32-panic, r=Amanieu
[rust.git] / src / test / ui / transmute / transmute-different-sizes.rs
1 // normalize-stderr-test "\d+ bits" -> "N bits"
2
3 // Tests that `transmute` cannot be called on types of different size.
4
5 #![allow(warnings)]
6 #![feature(specialization)]
7
8 use std::mem::transmute;
9
10 unsafe fn f() {
11     let _: i8 = transmute(16i16);
12     //~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
13 }
14
15 unsafe fn g<T>(x: &T) {
16     let _: i8 = transmute(x);
17     //~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
18 }
19
20 trait Specializable { type Output; }
21
22 impl<T> Specializable for T {
23     default type Output = u16;
24 }
25
26 unsafe fn specializable<T>(x: u16) -> <T as Specializable>::Output {
27     transmute(x)
28     //~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
29 }
30
31 fn main() {}