about summary refs log tree commit diff
path: root/tests/ui/mir/validate/validate-unsize-cast.rs
blob: 198af8d2e13a91054eb932c3b9396eb58e628ced (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
25
26
27
28
29
30
31
32
33
//@ compile-flags: -Zmir-opt-level=0 -Zmir-enable-passes=+Inline,+GVN -Zvalidate-mir

#![feature(unsize)]

use std::marker::Unsize;

pub trait CastTo<U: ?Sized>: Unsize<U> {}

// Not well-formed!
impl<T: ?Sized, U: ?Sized> CastTo<U> for T {}
//~^ ERROR the trait bound `T: Unsize<U>` is not satisfied

pub trait Cast {
    fn cast<U: ?Sized>(&self)
    where
        Self: CastTo<U>;
}
impl<T: ?Sized> Cast for T {
    #[inline(always)]
    fn cast<U: ?Sized>(&self)
    where
        Self: CastTo<U>,
    {
        let x: &U = self;
    }
}

fn main() {
    // When we inline this call, then we run GVN, then
    // GVN tries to evaluate the `() -> [i32]` unsize.
    // That's invalid!
    ().cast::<[i32]>();
}