]> git.lizzy.rs Git - rust.git/blob - src/test/ui/weird-exprs.rs
Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbini
[rust.git] / src / test / ui / weird-exprs.rs
1 // run-pass
2
3 #![feature(generators)]
4
5 #![allow(non_camel_case_types)]
6 #![allow(dead_code)]
7 #![allow(unreachable_code)]
8 #![allow(unused_braces, unused_must_use, unused_parens)]
9
10 #![recursion_limit = "256"]
11
12 use std::cell::Cell;
13 use std::mem::swap;
14
15 // Just a grab bag of stuff that you wouldn't want to actually write.
16
17 fn strange() -> bool { let _x: bool = return true; }
18
19 fn funny() {
20     fn f(_x: ()) { }
21     f(return);
22 }
23
24 fn what() {
25     fn the(x: &Cell<bool>) {
26         return while !x.get() { x.set(true); };
27     }
28     let i = &Cell::new(false);
29     let dont = {||the(i)};
30     dont();
31     assert!((i.get()));
32 }
33
34 fn zombiejesus() {
35     loop {
36         while (return) {
37             if (return) {
38                 match (return) {
39                     1 => {
40                         if (return) {
41                             return
42                         } else {
43                             return
44                         }
45                     }
46                     _ => { return }
47                 };
48             } else if (return) {
49                 return;
50             }
51         }
52         if (return) { break; }
53     }
54 }
55
56 fn notsure() {
57     let mut _x: isize;
58     let mut _y = (_x = 0) == (_x = 0);
59     let mut _z = (_x = 0) < (_x = 0);
60     let _a = (_x += 0) == (_x = 0);
61     let _b = swap(&mut _y, &mut _z) == swap(&mut _y, &mut _z);
62 }
63
64 fn canttouchthis() -> usize {
65     fn p() -> bool { true }
66     let _a = (assert!((true)) == (assert!(p())));
67     let _c = (assert!((p())) == ());
68     let _b: bool = (println!("{}", 0) == (return 0));
69 }
70
71 fn angrydome() {
72     loop { if break { } }
73     let mut i = 0;
74     loop { i += 1; if i == 1 { match (continue) { 1 => { }, _ => panic!("wat") } }
75       break; }
76 }
77
78 fn evil_lincoln() { let _evil = println!("lincoln"); }
79
80 fn dots() {
81     assert_eq!(String::from(".................................................."),
82                format!("{:?}", .. .. .. .. .. .. .. .. .. .. .. .. ..
83                                .. .. .. .. .. .. .. .. .. .. .. ..));
84 }
85
86 fn u8(u8: u8) {
87     if u8 != 0u8 {
88         assert_eq!(8u8, {
89             macro_rules! u8 {
90                 (u8) => {
91                     mod u8 {
92                         pub fn u8<'u8: 'u8 + 'u8>(u8: &'u8 u8) -> &'u8 u8 {
93                             "u8";
94                             u8
95                         }
96                     }
97                 };
98             }
99
100             u8!(u8);
101             let &u8: &u8 = u8::u8(&8u8);
102             ::u8(0u8);
103             u8
104         });
105     }
106 }
107
108 fn fishy() {
109     assert_eq!(String::from("><>"),
110                String::<>::from::<>("><>").chars::<>().rev::<>().collect::<String>());
111 }
112
113 fn union() {
114     union union<'union> { union: &'union union<'union>, }
115 }
116
117 fn special_characters() {
118     let val = !((|(..):(_,_),__@_|__)((&*"\\",'🤔')/**/,{})=={&[..=..][..];})//
119     ;
120     assert!(!val);
121 }
122
123 fn punch_card() -> impl std::fmt::Debug {
124     ..=..=.. ..    .. .. .. ..    .. .. .. ..    .. ..=.. ..
125     ..=.. ..=..    .. .. .. ..    .. .. .. ..    ..=..=..=..
126     ..=.. ..=..    ..=.. ..=..    .. ..=..=..    .. ..=.. ..
127     ..=..=.. ..    ..=.. ..=..    ..=.. .. ..    .. ..=.. ..
128     ..=.. ..=..    ..=.. ..=..    .. ..=.. ..    .. ..=.. ..
129     ..=.. ..=..    ..=.. ..=..    .. .. ..=..    .. ..=.. ..
130     ..=.. ..=..    .. ..=..=..    ..=..=.. ..    .. ..=.. ..
131 }
132
133 fn r#match() {
134     let val = match match match match match () {
135         () => ()
136     } {
137         () => ()
138     } {
139         () => ()
140     } {
141         () => ()
142     } {
143         () => ()
144     };
145     assert_eq!(val, ());
146 }
147
148 fn i_yield() {
149     static || {
150         yield yield yield yield yield yield yield yield yield;
151     };
152 }
153
154 fn match_nested_if() {
155     let val = match () {
156         () if if if if true {true} else {false} {true} else {false} {true} else {false} => true,
157         _ => false,
158     };
159     assert!(val);
160 }
161
162 fn monkey_barrel() {
163     let val = ()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=();
164     assert_eq!(val, ());
165 }
166
167 pub fn main() {
168     strange();
169     funny();
170     what();
171     zombiejesus();
172     notsure();
173     canttouchthis();
174     angrydome();
175     evil_lincoln();
176     dots();
177     u8(8u8);
178     fishy();
179     union();
180     special_characters();
181     punch_card();
182     r#match();
183     i_yield();
184     match_nested_if();
185     monkey_barrel();
186 }