]> git.lizzy.rs Git - rust.git/blob - tests/ui/trivial-bounds/trivial-bounds-inconsistent.rs
Rollup merge of #106470 - ehuss:tidy-no-wasm, r=Mark-Simulacrum
[rust.git] / tests / ui / trivial-bounds / trivial-bounds-inconsistent.rs
1 // run-pass
2
3 // Check that tautalogically false bounds are accepted, and are used
4 // in type inference.
5 #![feature(trivial_bounds)]
6 #![allow(unused)]
7
8 pub trait Foo {
9     fn test(&self);
10 }
11
12 fn generic_function<X: Foo>(x: X) {}
13
14 enum E where i32: Foo { V } //~ WARNING trivial_bounds
15
16 struct S where i32: Foo; //~ WARNING trivial_bounds
17
18 trait T where i32: Foo {} //~ WARNING trivial_bounds
19
20 union U where i32: Foo { f: i32 } //~ WARNING trivial_bounds
21
22 type Y where i32: Foo = ();
23 //~^ WARNING type_alias_bounds
24 //~| WARNING trivial_bounds
25
26 impl Foo for () where i32: Foo { //~ WARNING trivial_bounds
27     fn test(&self) {
28         3i32.test();
29         Foo::test(&4i32);
30         generic_function(5i32);
31     }
32 }
33
34 fn f() where i32: Foo { //~ WARNING trivial_bounds
35     let s = S;
36     3i32.test();
37     Foo::test(&4i32);
38     generic_function(5i32);
39 }
40
41 fn g() where &'static str: Foo { //~ WARNING trivial_bounds
42     "Foo".test();
43     Foo::test(&"Foo");
44     generic_function("Foo");
45 }
46
47 trait A {}
48
49 impl A for i32 {}
50
51 struct Dst<X: ?Sized> {
52     x: X,
53 }
54
55 struct TwoStrs(str, str) where str: Sized; //~ WARNING trivial_bounds
56
57 fn unsized_local() where for<'a> Dst<dyn A + 'a>: Sized { //~ WARNING trivial_bounds
58     let x: Dst<dyn A> = *(Box::new(Dst { x: 1 }) as Box<Dst<dyn A>>);
59 }
60
61 fn return_str() -> str where str: Sized { //~ WARNING trivial_bounds
62     *"Sized".to_string().into_boxed_str()
63 }
64
65 fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> {
66     //~^ WARNING trivial_bounds
67     -s
68 }
69
70 fn use_for() where i32: Iterator { //~ WARNING trivial_bounds
71     for _ in 2i32 {}
72 }
73
74 fn main() {}