rust/tests/ui/unsized/unsized2.rs

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

97 lines
1.6 KiB
Rust
Raw Normal View History

//@ run-pass
#![allow(unconditional_recursion)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// Test sized-ness checking in substitution.
use std::marker;
// Unbounded.
2014-12-24 07:05:30 +00:00
fn f1<X: ?Sized>(x: &X) {
f1::<X>(x);
}
fn f2<X>(x: &X) {
f1::<X>(x);
f2::<X>(x);
}
// Bounded.
trait T { fn dummy(&self) { } }
2014-12-24 07:05:30 +00:00
fn f3<X: T+?Sized>(x: &X) {
f3::<X>(x);
}
fn f4<X: T>(x: &X) {
f3::<X>(x);
f4::<X>(x);
}
// Self type.
2015-01-06 03:13:38 +00:00
trait T2 {
fn f() -> Box<Self>;
}
struct S;
impl T2 for S {
fn f() -> Box<S> {
Box::new(S)
}
}
2014-12-24 07:05:30 +00:00
fn f5<X: ?Sized+T2>(x: &X) {
let _: Box<X> = T2::f();
}
fn f6<X: T2>(x: &X) {
let _: Box<X> = T2::f();
}
2015-01-06 03:13:38 +00:00
trait T3 {
fn f() -> Box<Self>;
}
impl T3 for S {
fn f() -> Box<S> {
Box::new(S)
}
}
2014-12-24 07:05:30 +00:00
fn f7<X: ?Sized+T3>(x: &X) {
// This is valid, but the unsized bound on X is irrelevant because any type
// which implements T3 must have statically known size.
let _: Box<X> = T3::f();
}
trait T4<X> {
fn dummy(&self) { }
2019-05-28 18:47:21 +00:00
fn m1(&self, x: &dyn T4<X>, y: X);
fn m2(&self, x: &dyn T5<X>, y: X);
}
2014-12-24 07:05:30 +00:00
trait T5<X: ?Sized> {
fn dummy(&self) { }
2014-04-20 06:53:37 +00:00
// not an error (for now)
2019-05-28 18:47:21 +00:00
fn m1(&self, x: &dyn T4<X>);
fn m2(&self, x: &dyn T5<X>);
}
trait T6<X: T> {
fn dummy(&self) { }
2019-05-28 18:47:21 +00:00
fn m1(&self, x: &dyn T4<X>);
fn m2(&self, x: &dyn T5<X>);
}
2014-12-24 07:05:30 +00:00
trait T7<X: ?Sized+T> {
fn dummy(&self) { }
2014-04-20 06:53:37 +00:00
// not an error (for now)
2019-05-28 18:47:21 +00:00
fn m1(&self, x: &dyn T4<X>);
fn m2(&self, x: &dyn T5<X>);
}
2016-10-24 18:55:56 +00:00
// The last field in a struct may be unsized
2014-12-24 07:05:30 +00:00
struct S2<X: ?Sized> {
f: X,
}
2014-12-24 07:05:30 +00:00
struct S3<X: ?Sized> {
f1: isize,
f2: X,
}
pub fn main() {
}