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