]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/trait-suggest-where-clause.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / trait-suggest-where-clause.rs
1 // Copyright 2016 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 use std::mem;
12
13 struct Misc<T:?Sized>(T);
14
15 fn check<T: Iterator, U: ?Sized>() {
16 // suggest a where-clause, if needed
17 mem::size_of::<U>();
18 //~^ ERROR `U: std::marker::Sized` is not satisfied
19 //~| HELP E0277
20 //~| HELP consider adding a `where U: std::marker::Sized` bound
21 //~| NOTE required by `std::mem::size_of`
22
23 mem::size_of::<Misc<U>>();
24 //~^ ERROR `U: std::marker::Sized` is not satisfied
25 //~| HELP E0277
26 //~| HELP consider adding a `where U: std::marker::Sized` bound
27 //~| NOTE required because it appears within the type `Misc<U>`
28 //~| NOTE required by `std::mem::size_of`
29
30 // ... even if T occurs as a type parameter
31
32 <u64 as From<T>>::from;
33 //~^ ERROR `u64: std::convert::From<T>` is not satisfied
34 //~| HELP E0277
35 //~| HELP consider adding a `where u64: std::convert::From<T>` bound
36 //~| NOTE required by `std::convert::From::from`
37
38 <u64 as From<<T as Iterator>::Item>>::from;
39 //~^ ERROR `u64: std::convert::From<<T as std::iter::Iterator>::Item>` is not satisfied
40 //~| HELP E0277
41 //~| HELP consider adding a `where u64:
42 //~| NOTE required by `std::convert::From::from`
43
44 // ... but not if there are inference variables
45
46 <Misc<_> as From<T>>::from;
47 //~^ ERROR `Misc<_>: std::convert::From<T>` is not satisfied
48 //~| HELP E0277
49 //~| NOTE required by `std::convert::From::from`
50
51 // ... and also not if the error is not related to the type
52
53 mem::size_of::<[T]>();
54 //~^ ERROR `[T]: std::marker::Sized` is not satisfied
55 //~| HELP E0277
56 //~| NOTE `[T]` does not have a constant size
57 //~| NOTE required by `std::mem::size_of`
58
59 mem::size_of::<[&U]>();
60 //~^ ERROR `[&U]: std::marker::Sized` is not satisfied
61 //~| HELP E0277
62 //~| NOTE `[&U]` does not have a constant size
63 //~| NOTE required by `std::mem::size_of`
64 }
65
66 fn main() {
67 }