My name is Michael Gattozzi and today I want to bring you on a journey from

Weird Expressions and Where to Find Them

submited by
Style Pass
2022-08-06 00:00:07

My name is Michael Gattozzi and today I want to bring you on a journey from "What?" to "No way that works" to "Wait why does that work?!" and then true understanding and acceptance. Many an article or talk has been created about "Idiomatic Rust" or "Proper Code" or whatever else the kids say these days. However, I've spent a long time gazing into the "non-idiomatic" abyss of the weird-exprs.rs test file. A file which contains the kinds of programs that are non-sensical Rust, but technically correct Rust, the best kind of correct. A file hidden deep in the bowels of the Rust Compiler Test Suite designed to protect against messing up parsing rules and testing weird edge cases that rustc must accept, even if we don't want it too. A test file known to the compiler devs as a necessary evil and sequestered from the public lest it make both old and new Rustaceans run away in abject horror. A test file that shows just what kinds of wretched programs mortals are capable of inflicting upon the the world.

In the beginning there was commit (664b0ad)3fcead4fe4d22c05065a82a338770c429 made on August 19th, 2011. In it was a file wierd-exprs.rs, this was a mistake that was not noticed for a few commits and then renamed to weird-exprs.rs on Sep 26, 2011. This file will be 11 years old in two weeks. It's been around for quite some time, because no matter what point in time the language exists at we have valid programs that we can write because of how the language is structured, that we wouldn't want to write, but we should still test for to make sure we don't break any edge cases and invariants. There are a lot of programs that rustc can accept and produce code for, but that we as programmers would find are not easy to read, helpful, or do anything we'd actually want a computer to do. This test suite has an equivalent analogy in the English sentence Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo. It follows all of the correct grammar of the language, however, it is nonsensical, but is also technically allowed. weird-exprs.rs is the same thing. Here is one of those test cases from the file and trust me when I say this is the least gnarly one to look at.

Leave a Comment