]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/trait-bounds-on-structs-and-enums.rs
auto merge of #16408 : steveklabnik/rust/guide_iterators, r=brson
[rust.git] / src / test / compile-fail / trait-bounds-on-structs-and-enums.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 trait Trait {}
12
13 struct Foo<T:Trait> {
14     x: T,
15 }
16
17 enum Bar<T:Trait> {
18     ABar(int),
19     BBar(T),
20     CBar(uint),
21 }
22
23 fn explode(x: Foo<uint>) {}
24 //~^ ERROR failed to find an implementation
25 //~^^ ERROR instantiating a type parameter with an incompatible type
26
27 fn kaboom(y: Bar<f32>) {}
28 //~^ ERROR failed to find an implementation
29 //~^^ ERROR instantiating a type parameter with an incompatible type
30
31 impl<T> Foo<T> {
32     fn uhoh() {}
33 }
34
35 struct Baz {
36 //~^ ERROR failed to find an implementation
37 //~^^ ERROR instantiating a type parameter with an incompatible type
38     a: Foo<int>,
39 }
40
41 enum Boo {
42 //~^ ERROR failed to find an implementation
43 //~^^ ERROR instantiating a type parameter with an incompatible type
44     Quux(Bar<uint>),
45 }
46
47 struct Badness<T> {
48 //~^ ERROR failed to find an implementation
49 //~^^ ERROR instantiating a type parameter with an incompatible type
50     b: Foo<T>,
51 }
52
53 enum MoreBadness<T> {
54 //~^ ERROR failed to find an implementation
55 //~^^ ERROR instantiating a type parameter with an incompatible type
56     EvenMoreBadness(Bar<T>),
57 }
58
59 trait PolyTrait<T> {
60     fn whatever() {}
61 }
62
63 struct Struct;
64
65 impl PolyTrait<Foo<uint>> for Struct {
66 //~^ ERROR failed to find an implementation
67 //~^^ ERROR instantiating a type parameter with an incompatible type
68     fn whatever() {}
69 }
70
71 fn main() {
72     let bar: Bar<f64> = return;
73     //~^ ERROR failed to find an implementation
74     //~^^ ERROR instantiating a type parameter with an incompatible type
75     let _ = bar;
76 }
77