os-rust/tests/ui/transmute/transmute-fat-pointers.rs

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

34 lines
809 B
Rust
Raw Normal View History

//@ normalize-stderr-test: "\d+ bits" -> "N bits"
2018-08-10 22:46:59 +01:00
// Tests that are conservative around thin/fat pointer mismatches.
#![allow(dead_code)]
use std::mem::transmute;
2015-01-06 10:16:49 +13:00
fn a<T, U: ?Sized>(x: &[T]) -> &U {
2018-12-21 14:15:47 +00:00
unsafe { transmute(x) } //~ ERROR cannot transmute between types of different sizes
}
2015-01-06 10:16:49 +13:00
fn b<T: ?Sized, U: ?Sized>(x: &T) -> &U {
2018-12-21 14:15:47 +00:00
unsafe { transmute(x) } //~ ERROR cannot transmute between types of different sizes
}
fn c<T, U>(x: &T) -> &U {
unsafe { transmute(x) }
}
fn d<T, U>(x: &[T]) -> &[U] {
unsafe { transmute(x) }
}
2015-01-06 10:16:49 +13:00
fn e<T: ?Sized, U>(x: &T) -> &U {
2018-12-21 14:15:47 +00:00
unsafe { transmute(x) } //~ ERROR cannot transmute between types of different sizes
}
2015-01-06 10:16:49 +13:00
fn f<T, U: ?Sized>(x: &T) -> &U {
2018-12-21 14:15:47 +00:00
unsafe { transmute(x) } //~ ERROR cannot transmute between types of different sizes
}
fn main() { }