aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/test_data/parser/ok/0035_weird_exprs.rs
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-14 19:32:05 +0100
committerDmitry <[email protected]>2020-08-14 19:32:05 +0100
commit178c3e135a2a249692f7784712492e7884ae0c00 (patch)
treeac6b769dbf7162150caa0c1624786a4dd79ff3be /crates/syntax/test_data/parser/ok/0035_weird_exprs.rs
parent06ff8e6c760ff05f10e868b5d1f9d79e42fbb49c (diff)
parentc2594daf2974dbd4ce3d9b7ec72481764abaceb5 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/syntax/test_data/parser/ok/0035_weird_exprs.rs')
-rw-r--r--crates/syntax/test_data/parser/ok/0035_weird_exprs.rs154
1 files changed, 154 insertions, 0 deletions
diff --git a/crates/syntax/test_data/parser/ok/0035_weird_exprs.rs b/crates/syntax/test_data/parser/ok/0035_weird_exprs.rs
new file mode 100644
index 000000000..8c1323163
--- /dev/null
+++ b/crates/syntax/test_data/parser/ok/0035_weird_exprs.rs
@@ -0,0 +1,154 @@
1//! Adapted from a `rustc` test, which can be found at
2//! https://github.com/rust-lang/rust/blob/6d34ec18c7d7e574553f6347ecf08e1e1c45c13d/src/test/run-pass/weird-exprs.rs.
3//!
4//! Reported to rust-analyzer in https://github.com/rust-analyzer/rust-analyzer/issues/290
5
6#![allow(non_camel_case_types)]
7#![allow(dead_code)]
8#![allow(unreachable_code)]
9#![allow(unused_parens)]
10
11#![recursion_limit = "128"]
12
13use std::cell::Cell;
14use std::mem::swap;
15
16// Just a grab bag of stuff that you wouldn't want to actually write.
17
18fn strange() -> bool { let _x: bool = return true; }
19
20fn funny() {
21 fn f(_x: ()) { }
22 f(return);
23}
24
25fn what() {
26 fn the(x: &Cell<bool>) {
27 return while !x.get() { x.set(true); };
28 }
29 let i = &Cell::new(false);
30 let dont = {||the(i)};
31 dont();
32 assert!((i.get()));
33}
34
35fn zombiejesus() {
36 loop {
37 while (return) {
38 if (return) {
39 match (return) {
40 1 => {
41 if (return) {
42 return
43 } else {
44 return
45 }
46 }
47 _ => { return }
48 };
49 } else if (return) {
50 return;
51 }
52 }
53 if (return) { break; }
54 }
55}
56
57fn notsure() {
58 let mut _x: isize;
59 let mut _y = (_x = 0) == (_x = 0);
60 let mut _z = (_x = 0) < (_x = 0);
61 let _a = (_x += 0) == (_x = 0);
62 let _b = swap(&mut _y, &mut _z) == swap(&mut _y, &mut _z);
63}
64
65fn canttouchthis() -> usize {
66 fn p() -> bool { true }
67 let _a = (assert!((true)) == (assert!(p())));
68 let _c = (assert!((p())) == ());
69 let _b: bool = (println!("{}", 0) == (return 0));
70}
71
72fn angrydome() {
73 loop { if break { } }
74 let mut i = 0;
75 loop { i += 1; if i == 1 { match (continue) { 1 => { }, _ => panic!("wat") } }
76 break; }
77}
78
79fn evil_lincoln() { let _evil = println!("lincoln"); }
80
81fn dots() {
82 assert_eq!(String::from(".................................................."),
83 format!("{:?}", .. .. .. .. .. .. .. .. .. .. .. .. ..
84 .. .. .. .. .. .. .. .. .. .. .. ..));
85}
86
87fn u8(u8: u8) {
88 if u8 != 0u8 {
89 assert_eq!(8u8, {
90 macro_rules! u8 {
91 (u8) => {
92 mod u8 {
93 pub fn u8<'u8: 'u8 + 'u8>(u8: &'u8 u8) -> &'u8 u8 {
94 "u8";
95 u8
96 }
97 }
98 };
99 }
100
101 u8!(u8);
102 let &u8: &u8 = u8::u8(&8u8);
103 crate::u8(0u8);
104 u8
105 });
106 }
107}
108
109fn fishy() {
110 assert_eq!(String::from("><>"),
111 String::<>::from::<>("><>").chars::<>().rev::<>().collect::<String>());
112}
113
114fn union() {
115 union union<'union> { union: &'union union<'union>, }
116}
117
118fn special_characters() {
119 let val = !((|(..):(_,_),__@_|__)((&*"\\",'🤔')/**/,{})=={&[..=..][..];})//
120 ;
121 assert!(!val);
122}
123
124fn punch_card() -> impl std::fmt::Debug {
125 ..=..=.. .. .. .. .. .. .. .. .. .. .. ..=.. ..
126 ..=.. ..=.. .. .. .. .. .. .. .. .. ..=..=..=..
127 ..=.. ..=.. ..=.. ..=.. .. ..=..=.. .. ..=.. ..
128 ..=..=.. .. ..=.. ..=.. ..=.. .. .. .. ..=.. ..
129 ..=.. ..=.. ..=.. ..=.. .. ..=.. .. .. ..=.. ..
130 ..=.. ..=.. ..=.. ..=.. .. .. ..=.. .. ..=.. ..
131 ..=.. ..=.. .. ..=..=.. ..=..=.. .. .. ..=.. ..
132}
133
134fn ktulhu() {
135 ;;;();;;;;;;;;()
136}
137
138pub fn main() {
139 strange();
140 funny();
141 what();
142 zombiejesus();
143 notsure();
144 canttouchthis();
145 angrydome();
146 evil_lincoln();
147 dots();
148 u8(8u8);
149 fishy();
150 union();
151 special_characters();
152 punch_card();
153 ktulhu();
154}