]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/unsized3.rs
auto merge of #16909 : carols10cents/rust/docs-links, r=alexcrichton
[rust.git] / src / test / compile-fail / unsized3.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test sized-ness checking in substitution.
12
13
14 // Unbounded.
15 fn f1<Sized? X>(x: &X) {
16     f2::<X>(x); //~ ERROR instantiating a type parameter with an incompatible type `X`, which does n
17 }
18 fn f2<X>(x: &X) {
19 }
20
21 // Bounded.
22 trait T for Sized? {}
23 fn f3<Sized? X: T>(x: &X) {
24     f4::<X>(x); //~ ERROR instantiating a type parameter with an incompatible type `X`, which does n
25 }
26 fn f4<X: T>(x: &X) {
27 }
28
29 // Test with unsized enum.
30 enum E<Sized? X> {
31     V(X),
32 }
33
34 fn f5<Y>(x: &Y) {}
35 fn f6<Sized? X>(x: &X) {}
36 fn f7<Sized? X>(x1: &E<X>, x2: &E<X>) {
37     f5(x1); //~ERROR instantiating a type parameter with an incompatible type `E<X>`, which does not
38     f6(x2); // ok
39 }
40
41
42 // Test with unsized struct.
43 struct S<Sized? X> {
44     x: X,
45 }
46
47 fn f8<Sized? X>(x1: &S<X>, x2: &S<X>) {
48     f5(x1); //~ERROR instantiating a type parameter with an incompatible type `S<X>`, which does not
49     f6(x2); // ok
50 }
51
52 // Test some tuples.
53 fn f9<Sized? X>(x1: Box<S<X>>, x2: Box<E<X>>) {
54     f5(&(*x1, 34i)); //~ERROR instantiating a type parameter with an incompatible type `(S<X>,int)`,
55     f5(&(32i, *x2)); //~ERROR instantiating a type parameter with an incompatible type `(int,E<X>)`,
56 }
57
58 // I would like these to fail eventually.
59 /*
60 // impl - bounded
61 trait T1<Z: T> {
62 }
63 struct S3<Sized? Y>;
64 impl<Sized? X: T> T1<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type
65 }
66
67 // impl - unbounded
68 trait T2<Z> {
69 }
70 impl<Sized? X> T2<X> for S3<X> { //ERROR instantiating a type parameter with an incompatible type `X
71 */
72
73 // impl - struct
74 trait T3<Sized? Z> {
75 }
76 struct S4<Y>;
77 impl<Sized? X> T3<X> for S4<X> { //~ ERROR instantiating a type parameter with an incompatible type
78 }
79
80
81 pub fn main() {
82 }