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