]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/unsized3.rs
rollup merge of #17355 : gamazeps/issue17210
[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 within fn bodies..
12
13
14 // Unbounded.
15 fn f1<Sized? X>(x: &X) {
16     f2::<X>(x);
17     //~^ ERROR the trait `core::kinds::Sized` is not implemented
18 }
19 fn f2<X>(x: &X) {
20 }
21
22 // Bounded.
23 trait T for Sized? {}
24 fn f3<Sized? X: T>(x: &X) {
25     f4::<X>(x);
26     //~^ ERROR the trait `core::kinds::Sized` is not implemented
27 }
28 fn f4<X: T>(x: &X) {
29 }
30
31 // Test with unsized enum.
32 enum E<Sized? X> {
33     V(X),
34 }
35
36 fn f5<Y>(x: &Y) {}
37 fn f6<Sized? X>(x: &X) {}
38 fn f7<Sized? X>(x1: &E<X>, x2: &E<X>) {
39     f5(x1);
40     //~^ ERROR the trait `core::kinds::Sized` is not implemented
41     f6(x2); // ok
42 }
43
44
45 // Test with unsized struct.
46 struct S<Sized? X> {
47     x: X,
48 }
49
50 fn f8<Sized? X>(x1: &S<X>, x2: &S<X>) {
51     f5(x1);
52     //~^ ERROR the trait `core::kinds::Sized` is not implemented
53     f6(x2); // ok
54 }
55
56 // Test some tuples.
57 fn f9<Sized? X>(x1: Box<S<X>>, x2: Box<E<X>>) {
58     f5(&(*x1, 34i));
59     //~^ ERROR the trait `core::kinds::Sized` is not implemented
60     f5(&(32i, *x2));
61     //~^ ERROR the trait `core::kinds::Sized` is not implemented
62 }
63
64 pub fn main() {
65 }