]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/unsized3.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.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 use std::marker;
14
15 // Unbounded.
16 fn f1<X: ?Sized>(x: &X) {
17 f2::<X>(x);
18 //~^ ERROR `X: std::marker::Sized` is not satisfied
19 }
20 fn f2<X>(x: &X) {
21 }
22
23 // Bounded.
24 trait T {
25 fn foo(&self) { }
26 }
27 fn f3<X: ?Sized + T>(x: &X) {
28 f4::<X>(x);
29 //~^ ERROR `X: std::marker::Sized` is not satisfied
30 }
31 fn f4<X: T>(x: &X) {
32 }
33
34 // Test with unsized enum.
35 enum E<X: ?Sized> {
36 V(X),
37 }
38
39 fn f5<Y>(x: &Y) {}
40 fn f6<X: ?Sized>(x: &X) {}
41 fn f7<X: ?Sized>(x1: &E<X>, x2: &E<X>) {
42 f5(x1);
43 //~^ ERROR `X: std::marker::Sized` is not satisfied
44 f6(x2); // ok
45 }
46
47
48 // Test with unsized struct.
49 struct S<X: ?Sized> {
50 x: X,
51 }
52
53 fn f8<X: ?Sized>(x1: &S<X>, x2: &S<X>) {
54 f5(x1);
55 //~^ ERROR `X: std::marker::Sized` is not satisfied
56 f6(x2); // ok
57 }
58
59 // Test some tuples.
60 fn f9<X: ?Sized>(x1: Box<S<X>>, x2: Box<E<X>>) {
61 f5(&(*x1, 34));
62 //~^ ERROR `X: std::marker::Sized` is not satisfied
63 }
64
65 fn f10<X: ?Sized>(x1: Box<S<X>>, x2: Box<E<X>>) {
66 f5(&(32, *x2));
67 //~^ ERROR `X: std::marker::Sized` is not satisfied
68 }
69
70 pub fn main() {
71 }