]> git.lizzy.rs Git - rust.git/blob - src/test/ui/weird-exprs.rs
Require Drop impls to have the same constness on its bounds as the bounds on the...
[rust.git] / src / test / ui / weird-exprs.rs
1 // run-pass
2
3 #![feature(generators)]
4 #![feature(unboxed_closures, fn_traits)]
5
6 #![allow(non_camel_case_types)]
7 #![allow(dead_code)]
8 #![allow(unreachable_code)]
9 #![allow(unused_braces, unused_must_use, unused_parens)]
10 #![allow(uncommon_codepoints, confusable_idents)]
11
12 #![recursion_limit = "256"]
13
14 use std::cell::Cell;
15 use std::mem::swap;
16
17 // Just a grab bag of stuff that you wouldn't want to actually write.
18
19 fn strange() -> bool { let _x: bool = return true; }
20
21 fn funny() {
22     fn f(_x: ()) { }
23     f(return);
24 }
25
26 fn what() {
27     fn the(x: &Cell<bool>) {
28         return while !x.get() { x.set(true); };
29     }
30     let i = &Cell::new(false);
31     let dont = {||the(i)};
32     dont();
33     assert!((i.get()));
34 }
35
36 fn zombiejesus() {
37     loop {
38         while (return) {
39             if (return) {
40                 match (return) {
41                     1 => {
42                         if (return) {
43                             return
44                         } else {
45                             return
46                         }
47                     }
48                     _ => { return }
49                 };
50             } else if (return) {
51                 return;
52             }
53         }
54         if (return) { break; }
55     }
56 }
57
58 fn notsure() {
59     let mut _x: isize;
60     let mut _y = (_x = 0) == (_x = 0);
61     let mut _z = (_x = 0) < (_x = 0);
62     let _a = (_x += 0) == (_x = 0);
63     let _b = swap(&mut _y, &mut _z) == swap(&mut _y, &mut _z);
64 }
65
66 fn canttouchthis() -> usize {
67     fn p() -> bool { true }
68     let _a = (assert!((true)) == (assert!(p())));
69     let _c = (assert!((p())) == ());
70     let _b: bool = (println!("{}", 0) == (return 0));
71 }
72
73 fn angrydome() {
74     loop { if break { } }
75     let mut i = 0;
76     loop { i += 1; if i == 1 { match (continue) { 1 => { }, _ => panic!("wat") } }
77       break; }
78 }
79
80 fn evil_lincoln() { let _evil = println!("lincoln"); }
81
82 fn dots() {
83     assert_eq!(String::from(".................................................."),
84                format!("{:?}", .. .. .. .. .. .. .. .. .. .. .. .. ..
85                                .. .. .. .. .. .. .. .. .. .. .. ..));
86 }
87
88 fn u8(u8: u8) {
89     if u8 != 0u8 {
90         assert_eq!(8u8, {
91             macro_rules! u8 {
92                 (u8) => {
93                     mod u8 {
94                         pub fn u8<'u8: 'u8 + 'u8>(u8: &'u8 u8) -> &'u8 u8 {
95                             "u8";
96                             u8
97                         }
98                     }
99                 };
100             }
101
102             u8!(u8);
103             let &u8: &u8 = u8::u8(&8u8);
104             ::u8(0u8);
105             u8
106         });
107     }
108 }
109
110 fn fishy() {
111     assert_eq!(String::from("><>"),
112                String::<>::from::<>("><>").chars::<>().rev::<>().collect::<String>());
113 }
114
115 fn union() {
116     union union<'union> { union: &'union union<'union>, }
117 }
118
119 fn special_characters() {
120     let val = !((|(..):(_,_),(|__@_|__)|__)((&*"\\",'🤔')/**/,{})=={&[..=..][..];})//
121     ;
122     assert!(!val);
123 }
124
125 fn punch_card() -> impl std::fmt::Debug {
126     ..=..=.. ..    .. .. .. ..    .. .. .. ..    .. ..=.. ..
127     ..=.. ..=..    .. .. .. ..    .. .. .. ..    ..=..=..=..
128     ..=.. ..=..    ..=.. ..=..    .. ..=..=..    .. ..=.. ..
129     ..=..=.. ..    ..=.. ..=..    ..=.. .. ..    .. ..=.. ..
130     ..=.. ..=..    ..=.. ..=..    .. ..=.. ..    .. ..=.. ..
131     ..=.. ..=..    ..=.. ..=..    .. .. ..=..    .. ..=.. ..
132     ..=.. ..=..    .. ..=..=..    ..=..=.. ..    .. ..=.. ..
133 }
134
135 fn r#match() {
136     let val = match match match match match () {
137         () => ()
138     } {
139         () => ()
140     } {
141         () => ()
142     } {
143         () => ()
144     } {
145         () => ()
146     };
147     assert_eq!(val, ());
148 }
149
150 fn i_yield() {
151     static || {
152         yield yield yield yield yield yield yield yield yield;
153     };
154 }
155
156 fn match_nested_if() {
157     let val = match () {
158         () if if if if true {true} else {false} {true} else {false} {true} else {false} => true,
159         _ => false,
160     };
161     assert!(val);
162 }
163
164 fn monkey_barrel() {
165     let val = ()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=();
166     assert_eq!(val, ());
167 }
168
169 fn 𝚌𝚘𝚗𝚝𝚒𝚗𝚞𝚎() {
170     type 𝚕𝚘𝚘𝚙 = i32;
171     fn 𝚋𝚛𝚎𝚊𝚔() -> 𝚕𝚘𝚘𝚙 {
172         let 𝚛𝚎𝚝𝚞𝚛𝚗 = 42;
173         return 𝚛𝚎𝚝𝚞𝚛𝚗;
174     }
175     assert_eq!(loop {
176         break 𝚋𝚛𝚎𝚊𝚔 ();
177     }, 42);
178 }
179
180 fn function() {
181     struct foo;
182     impl FnOnce<()> for foo {
183         type Output = foo;
184         extern "rust-call" fn call_once(self, _args: ()) -> Self::Output {
185             foo
186         }
187     }
188     let foo = foo () ()() ()()() ()()()() ()()()()();
189 }
190
191 fn bathroom_stall() {
192     let mut i = 1;
193     matches!(2, _|_|_|_|_|_ if (i+=1) != (i+=1));
194     assert_eq!(i, 13);
195 }
196
197 pub fn main() {
198     strange();
199     funny();
200     what();
201     zombiejesus();
202     notsure();
203     canttouchthis();
204     angrydome();
205     evil_lincoln();
206     dots();
207     u8(8u8);
208     fishy();
209     union();
210     special_characters();
211     punch_card();
212     r#match();
213     i_yield();
214     match_nested_if();
215     monkey_barrel();
216     𝚌𝚘𝚗𝚝𝚒𝚗𝚞𝚎();
217     function();
218     bathroom_stall();
219 }