rust/tests/ui/unsized/issue-71659.rs

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

33 lines
579 B
Rust
Raw Normal View History

2020-10-14 23:35:45 +00:00
#![feature(unsize)]
use std::marker::Unsize;
pub trait CastTo<T: ?Sized>: Unsize<T> {
fn cast_to(&self) -> &T;
}
2020-10-17 23:13:25 +00:00
impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U {
fn cast_to(&self) -> &T {
2020-10-14 23:35:45 +00:00
self
}
2020-10-17 23:13:25 +00:00
}
2020-10-14 23:35:45 +00:00
2020-10-17 23:13:25 +00:00
impl<T: ?Sized> Cast for T {}
pub trait Cast {
fn cast<T: ?Sized>(&self) -> &T
2020-10-14 23:35:45 +00:00
where
Self: CastTo<T>,
{
self
}
}
2020-10-17 23:13:25 +00:00
pub trait Foo: CastTo<[i32]> {}
impl Foo for [i32; 0] {}
2020-10-14 23:35:45 +00:00
fn main() {
2020-10-17 23:13:25 +00:00
let x: &dyn Foo = &[];
let x = x.cast::<[i32]>();
//~^ ERROR: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
2020-10-14 23:35:45 +00:00
}