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

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

37 lines
704 B
Rust
Raw Permalink Normal View History

2023-06-02 05:54:52 +00:00
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
2023-12-14 13:11:28 +01:00
//@[next] compile-flags: -Znext-solver
2023-06-02 05:54:52 +00:00
2020-10-15 08:35:45 +09:00
#![feature(unsize)]
use std::marker::Unsize;
pub trait CastTo<T: ?Sized>: Unsize<T> {
fn cast_to(&self) -> &T;
}
2020-10-18 08:13:25 +09:00
impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U {
fn cast_to(&self) -> &T {
2020-10-15 08:35:45 +09:00
self
}
2020-10-18 08:13:25 +09:00
}
2020-10-15 08:35:45 +09:00
2020-10-18 08:13:25 +09:00
impl<T: ?Sized> Cast for T {}
pub trait Cast {
fn cast<T: ?Sized>(&self) -> &T
2020-10-15 08:35:45 +09:00
where
Self: CastTo<T>,
{
self
}
}
2020-10-18 08:13:25 +09:00
pub trait Foo: CastTo<[i32]> {}
impl Foo for [i32; 0] {}
2020-10-15 08:35:45 +09:00
fn main() {
2020-10-18 08:13:25 +09:00
let x: &dyn Foo = &[];
let x = x.cast::<[i32]>();
//~^ ERROR: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
2020-10-15 08:35:45 +09:00
}