Subject:

Golfing rust features


Date: Message-Id: https://www.5snb.club/posts/2020/golfing-rust-features/
#![feature(arbitrary_self_genders)]
Tags: #hack(6)

Inspired by a post about using as many language extensions as possible in haskell, I decided to make a 60*4 block of nightmares that requires as many nightly rust features to compile as possible.

I’m not expecting it to work, or even run. My benchmark was just “compile”. I managed to get 17 features in my 60 by 4 block of code. No idea if this is any good or not.

#![feature(const_fn)]
#![feature(const_panic)]
#![feature(never_type)]
#![feature(const_mut_refs)]
#![feature(const_raw_ptr_deref)]
#![feature(const_in_array_repeat_expressions)]
#![feature(const_raw_ptr_to_usize_cast)]
#![feature(arbitrary_enum_discriminant)]
#![feature(crate_visibility_modifier)]
#![feature(const_generics)]
#![feature(non_ascii_idents)]
#![feature(or_patterns)]
#![feature(raw_ref_op)]
#![feature(repr128)]
#![feature(main)]
#![feature(start)]
#![feature(type_ascription)]

#[repr(u128)]crate enum O<const X:u8>{S(!)=1,N}union Y{y:!}#
[main]#[start]const fn (x:isize,y:*const*const u8)->isize{
let mut x=[O::N;4];unsafe{match*(&mut x[1]as*mut _){O::S(y|y
)if&raw mut x[1]as*mut O<4>as usize>1:usize=>y,_=>todo!()}}}

The haskell solution got a ratio of around 3 characters of source code per feature. The rust code is worse, at 14 characters per feature. I could probably get more dense at the cost of not having quite so many features.

Interesting to note is just how many places you are allowed to not have whitespace between tokens and the parser doesn’t complain.