Change DST syntax: type -> Sized?
closes #13367 [breaking-change] Use `Sized?` to indicate a dynamically sized type parameter or trait (used to be `type`). E.g., ``` trait Tr for Sized? {} fn foo<Sized? X: Share>(x: X) {} ```
This commit is contained in:
parent
6959931498
commit
a0cfda53c4
29 changed files with 215 additions and 178 deletions
|
|
@ -10,5 +10,5 @@
|
|||
|
||||
// error-pattern: instantiating a type parameter with an incompatible type
|
||||
fn bar<T: Sized>() { }
|
||||
fn foo<type T>() { bar::<T>() }
|
||||
fn foo<Sized? T>() { bar::<T>() }
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@
|
|||
|
||||
// error-pattern: instantiating a type parameter with an incompatible type
|
||||
fn bar<T: Sized>() { }
|
||||
fn foo<type T>() { bar::<Option<T>>() }
|
||||
fn foo<Sized? T>() { bar::<Option<T>>() }
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@
|
|||
struct Foo<T> { data: T }
|
||||
|
||||
fn bar<T: Sized>() { }
|
||||
fn foo<type T>() { bar::<Foo<T>>() }
|
||||
fn foo<Sized? T>() { bar::<Foo<T>>() }
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -12,45 +12,45 @@
|
|||
|
||||
|
||||
// Unbounded.
|
||||
fn f1<type X>(x: &X) {
|
||||
fn f1<Sized? X>(x: &X) {
|
||||
f2::<X>(x); //~ ERROR instantiating a type parameter with an incompatible type `X`, which does n
|
||||
}
|
||||
fn f2<X>(x: &X) {
|
||||
}
|
||||
|
||||
// Bounded.
|
||||
trait T for type {}
|
||||
fn f3<type X: T>(x: &X) {
|
||||
trait T for Sized? {}
|
||||
fn f3<Sized? X: T>(x: &X) {
|
||||
f4::<X>(x); //~ ERROR instantiating a type parameter with an incompatible type `X`, which does n
|
||||
}
|
||||
fn f4<X: T>(x: &X) {
|
||||
}
|
||||
|
||||
// Test with unsized enum.
|
||||
enum E<type X> {
|
||||
enum E<Sized? X> {
|
||||
V(X),
|
||||
}
|
||||
|
||||
fn f5<Y>(x: &Y) {}
|
||||
fn f6<type X>(x: &X) {}
|
||||
fn f7<type X>(x1: &E<X>, x2: &E<X>) {
|
||||
fn f6<Sized? X>(x: &X) {}
|
||||
fn f7<Sized? X>(x1: &E<X>, x2: &E<X>) {
|
||||
f5(x1); //~ERROR instantiating a type parameter with an incompatible type `E<X>`, which does not
|
||||
f6(x2); // ok
|
||||
}
|
||||
|
||||
|
||||
// Test with unsized struct.
|
||||
struct S<type X> {
|
||||
struct S<Sized? X> {
|
||||
x: X,
|
||||
}
|
||||
|
||||
fn f8<type X>(x1: &S<X>, x2: &S<X>) {
|
||||
fn f8<Sized? X>(x1: &S<X>, x2: &S<X>) {
|
||||
f5(x1); //~ERROR instantiating a type parameter with an incompatible type `S<X>`, which does not
|
||||
f6(x2); // ok
|
||||
}
|
||||
|
||||
// Test some tuples.
|
||||
fn f9<type X>(x1: Box<S<X>>, x2: Box<E<X>>) {
|
||||
fn f9<Sized? X>(x1: Box<S<X>>, x2: Box<E<X>>) {
|
||||
f5(&(*x1, 34i)); //~ERROR instantiating a type parameter with an incompatible type `(S<X>,int)`,
|
||||
f5(&(32i, *x2)); //~ERROR instantiating a type parameter with an incompatible type `(int,E<X>)`,
|
||||
}
|
||||
|
|
@ -60,20 +60,20 @@ fn f9<type X>(x1: Box<S<X>>, x2: Box<E<X>>) {
|
|||
// impl - bounded
|
||||
trait T1<Z: T> {
|
||||
}
|
||||
struct S3<type Y>;
|
||||
impl<type X: T> T1<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type
|
||||
struct S3<Sized? Y>;
|
||||
impl<Sized? X: T> T1<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type
|
||||
}
|
||||
|
||||
// impl - unbounded
|
||||
trait T2<Z> {
|
||||
}
|
||||
impl<type X> T2<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type `X`
|
||||
impl<Sized? X> T2<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type `X
|
||||
|
||||
// impl - struct
|
||||
trait T3<type Z> {
|
||||
trait T3<Sized? Z> {
|
||||
}
|
||||
struct S4<Y>;
|
||||
impl<type X> T3<X> for S4<X> { //ERROR instantiating a type parameter with an incompatible type `X`
|
||||
impl<Sized? X> T3<X> for S4<X> { //ERROR instantiating a type parameter with an incompatible type `X
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// Test that bounds are sized-compatible.
|
||||
|
||||
trait T {}
|
||||
fn f<type Y: T>() {
|
||||
fn f<Sized? Y: T>() {
|
||||
//~^ERROR incompatible bounds on type parameter Y, bound T does not allow unsized type
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@
|
|||
// except according to those terms.
|
||||
#![feature(struct_variant)]
|
||||
|
||||
// Test `type` types not allowed in fields.
|
||||
// Test `Sized?` types not allowed in fields.
|
||||
|
||||
struct S1<type X> {
|
||||
struct S1<Sized? X> {
|
||||
f1: X, //~ ERROR type `f1` is dynamically sized. dynamically sized types may only appear as the
|
||||
f2: int,
|
||||
}
|
||||
struct S2<type X> {
|
||||
struct S2<Sized? X> {
|
||||
f: int,
|
||||
g: X, //~ ERROR type `g` is dynamically sized. dynamically sized types may only appear as the ty
|
||||
h: int,
|
||||
}
|
||||
|
||||
enum E<type X> {
|
||||
enum E<Sized? X> {
|
||||
V1(X, int), //~ERROR type `X` is dynamically sized. dynamically sized types may only appear as t
|
||||
V2{f1: X, f: int}, //~ERROR type `f1` is dynamically sized. dynamically sized types may only app
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,37 +8,37 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test `type` local variables.
|
||||
// Test `Sized?` local variables.
|
||||
|
||||
|
||||
trait T for type {}
|
||||
trait T for Sized? {}
|
||||
|
||||
fn f1<type X>(x: &X) {
|
||||
fn f1<Sized? X>(x: &X) {
|
||||
let _: X; //~ERROR variable `_` has dynamically sized type `X`
|
||||
let _: (int, (X, int)); //~ERROR variable `_` has dynamically sized type `(int,(X,int))`
|
||||
let y: X; //~ERROR variable `y` has dynamically sized type `X`
|
||||
let y: (int, (X, int)); //~ERROR variable `y` has dynamically sized type `(int,(X,int))`
|
||||
}
|
||||
fn f2<type X: T>(x: &X) {
|
||||
fn f2<Sized? X: T>(x: &X) {
|
||||
let _: X; //~ERROR variable `_` has dynamically sized type `X`
|
||||
let _: (int, (X, int)); //~ERROR variable `_` has dynamically sized type `(int,(X,int))`
|
||||
let y: X; //~ERROR variable `y` has dynamically sized type `X`
|
||||
let y: (int, (X, int)); //~ERROR variable `y` has dynamically sized type `(int,(X,int))`
|
||||
}
|
||||
|
||||
fn f3<type X>(x1: Box<X>, x2: Box<X>, x3: Box<X>) {
|
||||
fn f3<Sized? X>(x1: Box<X>, x2: Box<X>, x3: Box<X>) {
|
||||
let y: X = *x1; //~ERROR variable `y` has dynamically sized type `X`
|
||||
let y = *x2; //~ERROR variable `y` has dynamically sized type `X`
|
||||
let (y, z) = (*x3, 4i); //~ERROR variable `y` has dynamically sized type `X`
|
||||
}
|
||||
fn f4<type X: T>(x1: Box<X>, x2: Box<X>, x3: Box<X>) {
|
||||
fn f4<Sized? X: T>(x1: Box<X>, x2: Box<X>, x3: Box<X>) {
|
||||
let y: X = *x1; //~ERROR variable `y` has dynamically sized type `X`
|
||||
let y = *x2; //~ERROR variable `y` has dynamically sized type `X`
|
||||
let (y, z) = (*x3, 4i); //~ERROR variable `y` has dynamically sized type `X`
|
||||
}
|
||||
|
||||
fn g1<type X>(x: X) {} //~ERROR variable `x` has dynamically sized type `X`
|
||||
fn g2<type X: T>(x: X) {} //~ERROR variable `x` has dynamically sized type `X`
|
||||
fn g1<Sized? X>(x: X) {} //~ERROR variable `x` has dynamically sized type `X`
|
||||
fn g2<Sized? X: T>(x: X) {} //~ERROR variable `x` has dynamically sized type `X`
|
||||
|
||||
pub fn main() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,20 +8,20 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test syntax checks for `type` keyword.
|
||||
// Test syntax checks for `Sized?` syntax.
|
||||
|
||||
trait T1 for type {}
|
||||
pub trait T2 for type {}
|
||||
trait T3<X: T1> for type: T2 {}
|
||||
trait T4<type X> {}
|
||||
trait T5<type X, Y> {}
|
||||
trait T6<Y, type X> {}
|
||||
trait T7<type X, type Y> {}
|
||||
trait T8<type X: T2> {}
|
||||
struct S1<type X>;
|
||||
enum E<type X> {}
|
||||
impl <type X> T1 for S1<X> {}
|
||||
fn f<type X>() {}
|
||||
trait T1 for Sized? {}
|
||||
pub trait T2 for Sized? {}
|
||||
trait T3<X: T1> for Sized?: T2 {}
|
||||
trait T4<Sized? X> {}
|
||||
trait T5<Sized? X, Y> {}
|
||||
trait T6<Y, Sized? X> {}
|
||||
trait T7<Sized? X, Sized? Y> {}
|
||||
trait T8<Sized? X: T2> {}
|
||||
struct S1<Sized? X>;
|
||||
enum E<Sized? X> {}
|
||||
impl <Sized? X> T1 for S1<X> {}
|
||||
fn f<Sized? X>() {}
|
||||
|
||||
pub fn main() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// Test sized-ness checking in substitution.
|
||||
|
||||
// Unbounded.
|
||||
fn f1<type X>(x: &X) {
|
||||
fn f1<Sized? X>(x: &X) {
|
||||
f1::<X>(x);
|
||||
}
|
||||
fn f2<X>(x: &X) {
|
||||
|
|
@ -22,8 +22,8 @@ fn f2<X>(x: &X) {
|
|||
}
|
||||
|
||||
// Bounded.
|
||||
trait T for type {}
|
||||
fn f3<type X: T>(x: &X) {
|
||||
trait T for Sized? {}
|
||||
fn f3<Sized? X: T>(x: &X) {
|
||||
f3::<X>(x);
|
||||
}
|
||||
fn f4<X: T>(x: &X) {
|
||||
|
|
@ -32,7 +32,7 @@ fn f4<X: T>(x: &X) {
|
|||
}
|
||||
|
||||
// Self type.
|
||||
trait T2 for type {
|
||||
trait T2 for Sized? {
|
||||
fn f() -> Box<Self>;
|
||||
}
|
||||
struct S;
|
||||
|
|
@ -41,14 +41,14 @@ impl T2 for S {
|
|||
box S
|
||||
}
|
||||
}
|
||||
fn f5<type X: T2>(x: &X) {
|
||||
fn f5<Sized? X: T2>(x: &X) {
|
||||
let _: Box<X> = T2::f();
|
||||
}
|
||||
fn f6<X: T2>(x: &X) {
|
||||
let _: Box<X> = T2::f();
|
||||
}
|
||||
|
||||
trait T3 for type {
|
||||
trait T3 for Sized? {
|
||||
fn f() -> Box<Self>;
|
||||
}
|
||||
impl T3 for S {
|
||||
|
|
@ -56,7 +56,7 @@ impl T3 for S {
|
|||
box S
|
||||
}
|
||||
}
|
||||
fn f7<type X: T3>(x: &X) {
|
||||
fn f7<Sized? X: 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();
|
||||
|
|
@ -66,7 +66,7 @@ trait T4<X> {
|
|||
fn m1(x: &T4<X>);
|
||||
fn m2(x: &T5<X>);
|
||||
}
|
||||
trait T5<type X> {
|
||||
trait T5<Sized? X> {
|
||||
// not an error (for now)
|
||||
fn m1(x: &T4<X>);
|
||||
fn m2(x: &T5<X>);
|
||||
|
|
@ -76,21 +76,21 @@ trait T6<X: T> {
|
|||
fn m1(x: &T4<X>);
|
||||
fn m2(x: &T5<X>);
|
||||
}
|
||||
trait T7<type X: T> {
|
||||
trait T7<Sized? X: T> {
|
||||
// not an error (for now)
|
||||
fn m1(x: &T4<X>);
|
||||
fn m2(x: &T5<X>);
|
||||
}
|
||||
|
||||
// The last field in a struct or variant may be unsized
|
||||
struct S2<type X> {
|
||||
struct S2<Sized? X> {
|
||||
f: X,
|
||||
}
|
||||
struct S3<type X> {
|
||||
struct S3<Sized? X> {
|
||||
f1: int,
|
||||
f2: X,
|
||||
}
|
||||
enum E<type X> {
|
||||
enum E<Sized? X> {
|
||||
V1(X),
|
||||
V2{x: X},
|
||||
V3(int, X),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue