rust/tests/ui/weird-exprs.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

303 lines
6.5 KiB
Rust
Raw Normal View History

//@ run-pass
2023-10-20 05:46:28 +08:00
#![feature(coroutines)]
#![allow(non_camel_case_types)]
#![allow(dead_code)]
#![allow(redundant_semicolons)]
#![allow(unreachable_code)]
#![allow(unused_braces, unused_must_use, unused_parens)]
#![allow(uncommon_codepoints, confusable_idents)]
#![allow(unused_imports)]
2022-11-06 08:22:31 +08:00
#![allow(unreachable_patterns)]
2013-10-23 16:49:18 +08:00
#![recursion_limit = "256"]
extern crate core;
2014-01-01 07:46:27 +08:00
use std::cell::Cell;
use std::mem::swap;
use std::ops::Deref;
2013-05-06 12:42:54 +08:00
// Just a grab bag of stuff that you wouldn't want to actually write.
2012-08-02 08:30:05 +08:00
fn strange() -> bool { let _x: bool = return true; }
fn funny() {
fn f(_x: ()) { }
2012-08-02 08:30:05 +08:00
f(return);
}
fn what() {
2014-10-02 13:10:09 +08:00
fn the(x: &Cell<bool>) {
2014-01-01 07:46:27 +08:00
return while !x.get() { x.set(true); };
}
2014-10-02 13:10:09 +08:00
let i = &Cell::new(false);
let dont = {||the(i)};
dont();
2014-01-01 07:46:27 +08:00
assert!((i.get()));
}
fn zombiejesus() {
loop {
2012-08-02 08:30:05 +08:00
while (return) {
if (return) {
2012-08-07 03:34:08 +08:00
match (return) {
2015-01-26 05:05:03 +08:00
1 => {
2012-08-02 08:30:05 +08:00
if (return) {
return
} else {
2012-08-02 08:30:05 +08:00
return
}
}
2012-08-04 10:59:04 +08:00
_ => { return }
};
2012-08-02 08:30:05 +08:00
} else if (return) {
return;
}
}
2012-08-02 08:30:05 +08:00
if (return) { break; }
}
}
fn notsure() {
let mut _x: isize;
let mut _y = (_x = 0) == (_x = 0);
2013-02-15 18:44:18 +08:00
let mut _z = (_x = 0) < (_x = 0);
let _a = (_x += 0) == (_x = 0);
let _b = swap(&mut _y, &mut _z) == swap(&mut _y, &mut _z);
}
fn canttouchthis() -> usize {
fn p() -> bool { true }
2013-03-29 09:39:09 +08:00
let _a = (assert!((true)) == (assert!(p())));
let _c = (assert!((p())) == ());
let _b: bool = (println!("{}", 0) == (return 0));
}
fn angrydome() {
loop { if break { } }
2015-01-26 05:05:03 +08:00
let mut i = 0;
loop { i += 1; if i == 1 { match (continue) { 1 => { }, _ => panic!("wat") } }
2012-08-24 05:44:58 +08:00
break; }
}
fn evil_lincoln() { let _evil: () = println!("lincoln"); }
2017-05-26 23:44:18 +08:00
fn dots() {
assert_eq!(String::from(".................................................."),
format!("{:?}", .. .. .. .. .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. .. .. .. .. .. ..));
2017-05-26 23:44:18 +08:00
}
fn u8(u8: u8) {
if u8 != 0u8 {
assert_eq!(8u8, {
macro_rules! u8 {
(u8) => {
mod u8 {
pub fn u8<'u8: 'u8 + 'u8>(u8: &'u8 u8) -> &'u8 u8 {
"u8";
u8
}
2017-05-26 23:44:18 +08:00
}
};
}
u8!(u8);
let &u8: &u8 = u8::u8(&8u8);
::u8(0u8);
u8
});
}
2017-05-26 23:44:18 +08:00
}
fn fishy() {
assert_eq!(String::from("><>"),
String::<>::from::<>("><>").chars::<>().rev::<>().collect::<String>());
2017-05-26 23:44:18 +08:00
}
2017-08-04 15:53:09 +08:00
fn union() {
union union<'union> { union: &'union union<'union>, }
}
fn special_characters() {
2022-05-21 06:17:33 +08:00
let val = !((|(..):(_,_),(|__@_|__)|__)((&*"\\",'🤔')/**/,{})=={&[..=..][..];})//
;
assert!(!val);
}
fn punch_card() -> impl std::fmt::Debug {
..=..=.. .. .. .. .. .. .. .. .. .. .. ..=.. ..
..=.. ..=.. .. .. .. .. .. .. .. .. ..=..=..=..
..=.. ..=.. ..=.. ..=.. .. ..=..=.. .. ..=.. ..
..=..=.. .. ..=.. ..=.. ..=.. .. .. .. ..=.. ..
..=.. ..=.. ..=.. ..=.. .. ..=.. .. .. ..=.. ..
..=.. ..=.. ..=.. ..=.. .. .. ..=.. .. ..=.. ..
..=.. ..=.. .. ..=..=.. ..=..=.. .. .. ..=.. ..
}
2019-03-31 21:20:10 +08:00
fn r#match() {
let val: () = match match match match match () {
2019-03-31 21:20:10 +08:00
() => ()
} {
() => ()
} {
() => ()
} {
() => ()
} {
() => ()
};
assert_eq!(val, ());
}
fn i_yield() {
static || {
yield yield yield yield yield yield yield yield yield;
};
}
2019-06-16 20:01:05 +08:00
fn match_nested_if() {
let val = match () {
() if if if if true {true} else {false} {true} else {false} {true} else {false} => true,
_ => false,
};
assert!(val);
}
fn monkey_barrel() {
let val: () = ()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=()=();
assert_eq!(val, ());
}
2022-05-21 06:17:33 +08:00
fn 𝚌𝚘𝚗𝚝𝚒𝚗𝚞𝚎() {
type 𝚕𝚘𝚘𝚙 = i32;
fn 𝚋𝚛𝚎𝚊𝚔() -> 𝚕𝚘𝚘𝚙 {
let 𝚛𝚎𝚝𝚞𝚛𝚗 = 42;
return 𝚛𝚎𝚝𝚞𝚛𝚗;
}
assert_eq!(loop {
break 𝚋𝚛𝚎𝚊𝚔 ();
2022-05-21 06:17:33 +08:00
}, 42);
}
fn function() {
struct foo;
impl Deref for foo {
type Target = fn() -> Self;
fn deref(&self) -> &Self::Target {
&((|| foo) as _)
}
}
let foo = foo () ()() ()()() ()()()() ()()()()();
}
fn bathroom_stall() {
let mut i = 1;
matches!(2, _|_|_|_|_|_ if (i+=1) != (i+=1));
assert_eq!(i, 13);
}
2022-11-06 08:22:31 +08:00
fn closure_matching() {
let x = |_| Some(1);
let (|x| x) = match x(..) {
|_| Some(2) => |_| Some(3),
|_| _ => unreachable!(),
};
assert!(matches!(x(..), |_| Some(4)));
}
fn semisemisemisemisemi() {
;;;;;;; ;;;;;;; ;;; ;;; ;;
;; ;; ;;;; ;;;; ;;
;;;;;;; ;;;;; ;; ;;;; ;; ;;
;; ;; ;; ;; ;; ;;
;;;;;;; ;;;;;;; ;; ;; ;;
}
fn useful_syntax() {
use {{std::{{collections::{{HashMap}}}}}};
use ::{{{{core}, {std}}}};
use {{::{{core as core2}}}};
}
fn infcx() {
pub mod cx {
pub mod cx {
pub use super::cx;
pub struct Cx;
}
}
let _cx: cx::cx::Cx = cx::cx::cx::cx::cx::Cx;
}
2023-12-17 06:32:24 +08:00
fn return_already() -> impl std::fmt::Debug {
loop {
return !!!!!!!
break !!!!!!1111
}
}
fn fake_macros() -> impl std::fmt::Debug {
2023-12-17 06:32:24 +08:00
loop {
if! {
match! (
break! {
return! {
1337
}
}
)
{}
}
{}
}
}
fn fish_fight() {
trait Rope {
fn _____________<U>(_: Self, _: U) where Self: Sized {}
}
struct T;
impl Rope for T {}
fn tug_o_war(_: impl Fn(T, T)) {}
tug_o_war(<T>::_____________::<T>);
}
pub fn main() {
strange();
funny();
what();
zombiejesus();
notsure();
canttouchthis();
angrydome();
evil_lincoln();
2017-05-26 23:44:18 +08:00
dots();
u8(8u8);
2017-05-26 23:44:18 +08:00
fishy();
2017-08-04 15:53:09 +08:00
union();
2018-05-25 22:50:59 +08:00
special_characters();
punch_card();
2019-03-31 21:20:10 +08:00
r#match();
i_yield();
2019-06-16 20:01:05 +08:00
match_nested_if();
monkey_barrel();
2022-05-21 06:17:33 +08:00
𝚌𝚘𝚗𝚝𝚒𝚗𝚞𝚎();
function();
bathroom_stall();
2022-11-06 08:22:31 +08:00
closure_matching();
semisemisemisemisemi();
useful_syntax();
infcx();
2023-12-17 06:32:24 +08:00
return_already();
fake_macros();
fish_fight();
}