]> git.lizzy.rs Git - rust.git/blob - src/test/ui/feature-gate-trivial_bounds.rs
e72b8782e50d59fcb3e441a8e71f43d66be723a1
[rust.git] / src / test / ui / feature-gate-trivial_bounds.rs
1 // Copyright 2018 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 #![allow(unused)]
12 #![allow(type_alias_bounds)]
13
14 pub trait Foo {
15     fn test(&self);
16 }
17
18 fn generic_function<X: Foo>(x: X) {}
19
20 enum E where i32: Foo { V } //~ ERROR
21
22 struct S where i32: Foo; //~ ERROR
23
24 trait T where i32: Foo {} //~ ERROR
25
26 union U where i32: Foo { f: i32 } //~ ERROR
27
28 type Y where i32: Foo = (); // OK - bound is ignored
29
30 impl Foo for () where i32: Foo { //~ ERROR
31     fn test(&self) { //~ ERROR
32         3i32.test();
33         Foo::test(&4i32);
34         generic_function(5i32);
35     }
36 }
37
38 fn f() where i32: Foo //~ ERROR
39 {
40     let s = S;
41     3i32.test();
42     Foo::test(&4i32);
43     generic_function(5i32);
44 }
45
46 fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> { //~ ERROR
47     -s
48 }
49
50 fn use_for() where i32: Iterator { //~ ERROR
51     for _ in 2i32 {}
52 }
53
54 trait A {}
55
56 impl A for i32 {}
57
58 struct Dst<X: ?Sized> {
59     x: X,
60 }
61
62 struct TwoStrs(str, str) where str: Sized; //~ ERROR
63 //~^ ERROR
64
65 fn unsized_local() where Dst<A>: Sized { //~ ERROR
66     let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
67 }
68
69 fn return_str() -> str where str: Sized { //~ ERROR
70     *"Sized".to_string().into_boxed_str()
71 }
72
73 // This is currently accepted because the function pointer isn't
74 // considered global.
75 fn global_hr(x: fn(&())) where fn(&()): Foo { // OK
76     x.test();
77 }
78
79 fn main() {}