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