]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/unsized3.rs
New upstream version 1.24.1+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 fn f5<Y>(x: &Y) {}
35 fn f6<X: ?Sized>(x: &X) {}
36
37 // Test with unsized struct.
38 struct S<X: ?Sized> {
39 x: X,
40 }
41
42 fn f8<X: ?Sized>(x1: &S<X>, x2: &S<X>) {
43 f5(x1);
44 //~^ ERROR `X: std::marker::Sized` is not satisfied
45 f6(x2); // ok
46 }
47
48 // Test some tuples.
49 fn f9<X: ?Sized>(x1: Box<S<X>>) {
50 f5(&(*x1, 34));
51 //~^ ERROR `X: std::marker::Sized` is not satisfied
52 }
53
54 fn f10<X: ?Sized>(x1: Box<S<X>>) {
55 f5(&(32, *x1));
56 //~^ ERROR `X: std::marker::Sized` is not satisfied
57 //~| ERROR `X: std::marker::Sized` is not satisfied
58 }
59
60 pub fn main() {
61 }