]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/trait-suggest-where-clause.rs
Auto merge of #32990 - tbu-:pr_more_defaults_cstr_path, r=alexcrichton
[rust.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 consider adding a `where U: std::marker::Sized` bound
20     //~| NOTE required by `std::mem::size_of`
21
22     mem::size_of::<Misc<U>>();
23     //~^ ERROR `U: std::marker::Sized` is not satisfied
24     //~| HELP consider adding a `where U: std::marker::Sized` bound
25     //~| NOTE required because it appears within the type `Misc<U>`
26     //~| NOTE required by `std::mem::size_of`
27
28     // ... even if T occurs as a type parameter
29
30     <u64 as From<T>>::from;
31     //~^ ERROR `u64: std::convert::From<T>` is not satisfied
32     //~| HELP consider adding a `where u64: std::convert::From<T>` bound
33     //~| NOTE required by `std::convert::From::from`
34
35     <u64 as From<<T as Iterator>::Item>>::from;
36     //~^ ERROR `u64: std::convert::From<<T as std::iter::Iterator>::Item>` is not satisfied
37     //~| HELP consider adding a `where u64:
38     //~| NOTE required by `std::convert::From::from`
39
40     // ... but not if there are inference variables
41
42     <Misc<_> as From<T>>::from;
43     //~^ ERROR `Misc<_>: std::convert::From<T>` is not satisfied
44     //~| NOTE required by `std::convert::From::from`
45
46     // ... and also not if the error is not related to the type
47
48     mem::size_of::<[T]>();
49     //~^ ERROR `[T]: std::marker::Sized` is not satisfied
50     //~| NOTE `[T]` does not have a constant size
51     //~| NOTE required by `std::mem::size_of`
52
53     mem::size_of::<[&U]>();
54     //~^ ERROR `[&U]: std::marker::Sized` is not satisfied
55     //~| NOTE `[&U]` does not have a constant size
56     //~| NOTE required by `std::mem::size_of`
57 }
58
59 fn main() {
60 }