]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsized3.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / 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 the size for values of type
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 the size for values of type
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 the size for values of type
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 the size for values of type
52 }
53
54 fn f10<X: ?Sized>(x1: Box<S<X>>) {
55     f5(&(32, *x1));
56     //~^ ERROR the size for values of type
57     //~| ERROR the size for values of type
58 }
59
60 pub fn main() {
61 }