►
Description
Buried deep in the test suite of rustc exists a singular file, weird-exprs.rs, that has been around since 2011 that is filled with "technically legal" Rust. While it is far from idiomatic and makes many a Rustacean ask "why?" if not actively running away from the horror it presents, the test file is a document of what Rust has been and is today. It's also an example of things that need to be legal so we can write well formed Rust programs. This talk intends to dive into the history of the file as well as why any of it even works in the first place.
A
My
name
is
michael
gatosi,
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
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
experts.rs
test
file,
a
file
which
contains
the
kinds
of
programs
that
are
nonsensical,
rust
but
technically
correct,
rust.
A
In
the
beginning,
there
was
commit
664
b0ad
made
on
august
19
2011,
and
it
was
a
file
titled,
weird
experts,
dot
rs.
This
was
a
mistake
that
was
not
noticed
for
a
few
commits
and
then
renamed
to
weird
experts,
daughter
s
on
september
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.
A
There
are
a
lot
of
programs
that
rusty,
can't
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.
A
It
follows
all
the
correct
grammar
of
the
language.
However,
it
is
nonsensical,
but
is
also
technically
allowed
weird
experts
dot.
Our
s
is
the
same
thing.
Here's
one
of
those
test
cases
from
the
file
and
trust
me
when
I
say
this
is
the
least
gnarly
one
to
look
at
it.
Just
prints
lincoln
and
assigns
the
unit
type
returning
from
print
line
to
evil
sure
you
can
assign
the
unit
to
value
to
a
variable,
but
we
wouldn't
actually
want
to
do
that
in
the
code
rewrite.
This
is
what
I
mean
by
valid,
but
not
helpful
code.
A
Now
you
might
be
wondering
why
is
it
called
evil
lincoln?
Let's
look
at
it
in
the
original,
commit
that
added
it.
As
you
can
see,
print
line
used
to
be
called
log
and
for
anyone
not
up
to
date
on
u.s
presidential
history
lincoln
lived
in
a
log
cabin.
He
had
built
himself
in
illinois
back
in
the
day.
The
name
of
the
test
has
survived,
but
not
the
pre,
1.0,
syntax,
rust
and
what
it
looks
like
has
both
changed
a
lot
and
not
a
lot
in
the
11
years.
A
Since
this
test
was
added,
we
use
print
line,
a
macro,
not
log,
a
built-in
keyword
and
we
assign
with
equals
not
left
arrow.
These
days,
weird
experts.rs
has
existed
through
most
of
rust
creation
and
every
step
of
the
way.
Since
its
inception,
it
has
guarded
the
language
from
breaking
its
grammar
and
parsing
rules.
It
was
here
before
many
of
us
started
using
rus,
and
it
will
be
here
longer
than
many
of
us
will
be
now
that
we
understand
just
where
this
file
came
from.
A
Let's
start
looking
into
a
few
choice,
cases
to
learn
a
bit
more
about
how
russ
works
and,
let's
get
weird,
if
you
look
at
the
file
today,
you
can
see
these
allow
pragmas,
meaning
we're
going
to
have
a
good
time
because
we're
allowing
ourselves
to
use
the
good
code
do
note.
I
can't
cover
every
case
with
the
time
we
have
today,
and
so
I
have
chosen
the
ones
I
think
we
can
learn
the
most
from.
A
If
you
want
to
see
all
the
tests,
which
I
really
think
you
should
they're
absolutely
fascinating,
will
make
you
scratch
your
head
for
a
bit
as
you
figure
them
out,
then
I
suggest
reading
them
all
here
at
source
test,
ui,
weird
experts
and
the
rust
c
repo
commit
491
eb1.
Let's
talk
about,
if,
if
lets
you
test
some
expression
for
boolean
value
of
true
and
if
it's
true
executes
the
block
in
this
case,
we
check
it's
true
and
then
execute
the
print
line
macro.
A
We
can
also
have
an
optional
else
block
that
lets
us
do
something
in
case
it's
false
in
this
case
we'd
print
hello,
I'm
false!
Did
you
know
that,
if
is
an
expression,
though
in
rust,
and
not
a
statement,
this
means
it's
far
more
flexible
and
can
be
used
in
cases
that
expect
an
expression
such
as
variable
assignment.
A
A
In
this
case,
we
use
an
expression
block
which
will
execute
everything
inside
the
block.
First,
in
this
case,
we
print
the
sentence
evaluating
this
expression
block
before
evaluating
returning
wherever
the
final
value
is
without
a
semicolon.
In
this
case,
true,
something
to
note
about
expression
blocks
is
that
they
always
return
a
type
it
just
defaults
to
the
unit
type
if
there
is
no
type
now,
let's
talk
about
match
for
a
second,
it
is
also
an
expression
that
takes
an
expression,
in
this
case,
the
value
1,
which
is
a
u8
and
pattern
matches
on
it.
A
It
tests
the
patterns
in
order
of
writing
and
then
stops
at
the
first
one
that
matches
the
pattern,
and
then
it
executes
the
expression
to
the
right
of
it.
Russ
forces
you
to
match
every
possible
pattern,
and
so
we
can
use
underscore
as
the
catch-all
pattern
for
every
other
number
that
a
u8
can
be
in
this
example.
One
matches
on
one
and
prints.
I
am
one
we
can
go
even
further
with
match,
as
each
pattern
can
accept
an
optional
ifguard.
A
Alongside
the
pattern
here,
we
check
the
first
pattern
for
x
and
since
it's
the
catch-all
we
match
and
then
ask
if
x
is
even
we
see
that
it's
not
and
move
on
to
the
next
pattern.
We
know
the
pattern
will
match
and
the
check
is
odd,
which
it
is,
since
one
is
an
odd
number
and
then
print.
I
am
an
odd
number.
A
So,
let's
walk
through
what
this
test
is
doing.
We
first
match
on
the
unit
type
and
go
to
the
first
pattern.
We
see
the
pattern
is
the
unit
type,
and
so
now
we
need
to
check
the
nested.
If
statements,
we
evaluate
the
first
statement.
If
true
and
see
we
should
use
the
if
block,
not
the
else
block
which
evaluates
to
true.
A
We
then
use
the
true
value
from
the
first.
If,
as
the
input
to
the
second,
if
which
means
we
choose
the,
if
block
not
the
else
block
which
evaluates
to
true,
we
then
evaluate
the
third.
If
and
just
like
the
previous
two,
we
choose
the
if
block
and
not
the
else
block
which
evaluates
to
true,
then
we
check
the
last.
If
is
true
for
the
match
pattern
which
it
is,
and
so
we
choose
that
pattern
in
the
match
statement,
we
then
assign
the
value
true
to
the
variable
val.
A
We
then
assert
that
val
is
true,
which
it
is
and
so
the
test
passes.
Let's
kick
things
up
a
notch
and
talk
about
functions.
We
can
define
a
function
example
with
the
above
syntax
and
when
called
it
will
execute
anything
in
the
block.
In
this
case
it
will
print
out.
I
am
a
function.
Okay,
that's
easy!
Now
we
can
also
define
functions
for
types
like
so
here
we
have
a
struct
bar
that
we
imple
a
function.
A
Example
for
that
takes
bar
by
value
with
the
self
argument
and
then
prints
out,
I'm
a
function
that
takes
bar
as
input
now.
What
if
we
change
this,
that
it
also
returned
a
bar
instead
of
printing
out
something?
It
would
look
like
this,
where
the
only
difference
is
we're
returning
self,
which
is
an
alias
for
bar
here,
given
we're
inside
an
input
block.
This
would
let
us
write
some
interesting
code,
because
then
we
could
call
example
as
many
times
as
we
wanted
like
this.
A
We
could
keep
chaining
example
here,
because
we
create
a
new
bar
in
each
call,
to
example,
and
I
promise
this
is
going
somewhere.
I
want
to
talk
about
function
traits
for
a
second.
These.
Let
us
pass
functions
in
other
functions,
generically.
Here's
what
I
mean.
We
define
a
function
example
that
has
a
generic
parameter
f.
That
is
the
type
of
the
argument
function.
A
A
We
should
know
closures
implement
fn
once
as
do
named
functions.
So,
let's
recap:
we
could
define
functions
that
when
called
will
execute.
What's
inside
the
block,
we
can
implement
a
function
for
a
type
that
will
take
itself
as
the
input
we
can
have
a
function
return
itself
as
a
type,
and
we
can
therefore
call
a
function
over
and
over
and
over
again.
We
also
have
a
trait
fn
once
that
means
whatever
implements
it.
A
A
A
We
then
define
the
function
body
where
we
return
a
new
type
foo
after
taking
the
old
one
by
value
with
self
and
dropping
it
at
the
end
of
the
function
body.
We
then
kulfu
and
much
like
before,
when
we
kept
calling
example,
we
just
keep
invoking
foo
as
an
f
and
once
function
and
eventually
assign
foo
to
the
variable
foo.
A
Now,
let's
talk
about
loops
in
the
never
type.
With
loops,
we
have
a
loop
keyword
that
will
let
us
infinitely
run
the
code
inside
the
block.
We
can
end
a
loop
by
using
the
break
keyword
now.
Here's
a
neat
thing
loop
is
an
expression,
and
so
it
can
go
wherever
you
want
an
expression.
This
means
we
can
return
a
value
from
a
loop
like
so
here
we
return
a
value
5
from
the
loop
by
calling
break
and
assign
it
to
x.
We
then
assert
is
equal
to
5.
A
now
loops
also
have
one
other
keyword
continue,
which
means
stop
evaluating
this
loop
and
start
from
the
beginning.
Here
we
print
out
std,
outgo
bur
and
then
restart
the
loop
again
and
never
hit
the
unreachable
statement.
Okay,
so
we
know
a
bit
about
loops,
but
what
about
that
never
type
I
mentioned,
never
is
an
inbuilt
primitive.
Let's
take
a
look
at
a
quick
example
here.
The
exclamation
point
is
how
we
represent
the
never
type.
Since
we
return
from
the
function
early
with
the
value
1
2
3
we
can
never
assign
it
to
x.
A
A
Another
interesting
thing
is
that
these
keywords
that
are
never
can
type
check
to
anything,
as
you
will
never
need
the
type
for
that
part.
So,
for
example,
this
compiles
just
fine
as
we
exit
the
function
early
and
can't
assign
any
value
to
x,
no
matter
what
type
it
is.
Let's
recap,
then
we
have
a
loop
keyword
which
loops
infinitely.
We
can
use
break
to
exit
a
loop
or
exit
a
loop
and
return
a
value
we
can
use
continue
to
start
at
the
beginning
of
a
loop.
A
Some
control
flow
words
like
break
and
continue
are
what's
known
as
the
never
type
and
the
never
type
type
checks
as
any
type
with
this
we're
ready
to
look
at
our
next
case.
For
the
sake
of
brevity,
I'm
just
going
to
show
you
the
control
flow
of
this
handy
diagram,
I'm
kidding,
but
the
important
part
here
is
that
what
this
test
is
testing
for,
which
is
that
break
and
continue
can
be
used
anywhere
and
type
check,
while
still
letting
the
loop
execute
where
it
can
a
bit
nonsensical
for
control
flow,
but
absolutely
necessary.
A
We
also
have
strict
keywords,
which
means
these
words
cannot
be
used
as
a
name
of
items,
variables,
function,
parameters,
fields,
variants,
type,
parameters,
lifetime
parameters,
loop
labels,
macros
attributes,
macro
placeholders
or
crates
words
like
loop
return
and
fn
fall
into
this
category.
We
also
have
weak
keywords.
These
are
only
special
in
certain
contexts
and
so
can
be
used
in
places.
You
couldn't
use,
strict
keywords,
union
macro
rules
and
tick
static
are
the
weak
keywords.
A
A
A
A
We
then
assert
that
a
value
eight
of
type
u8
is
equal
to
the
return
value
of
an
expression
block
which
defines
a
macro
you
ate.
That
takes
the
literal
token
you
ate
to
define
a
module
you
ate
with
a
function
named
u8
with
a
lifetime
tickuate
that
must
outlive
the
lifetimes
tickuate
and
tickuate.
With
an
argument,
you
ate
that's
a
reftikuate
of
a
u8
that
returns
a
ref.
Take
you
wait
of
type
u8
in
that
function.
It
creates
an
ref
static
stir
with
the
value
you
ate
and
returns
the
function
argument
u8.
A
We
then
call
the
macro
u8.
With
the
argument
you
ate,
create
a
variable
named
refu8
with
type
refu8
to
assign
it
rough
8u8
as
the
value.
After
calling
the
function
you
ate
from
the
module
you
ate,
and
then
we
called
the
original
function,
u8
recursively
with
the
value
0ua,
which
hits
the
if
statement
and
returns
and
then
return
the
value
u8
from
the
block
which
in
this
case
is
8.
Since
we
pass
in
that
value
in
the
test
case,
meaning
8
is
equal
to
8.,
see
not
hard
to
understand
just
hard
to
parse.
A
It's
been
a
short
yet
dense
journey
that
I've
taken
you
on
today,
we've
seen
a
lot,
maybe
too
much
for
mortal
eyes,
and
I
sincerely
apologize
for
showing
you
even
a
fraction
of
the
weird
experts
rs
test
file,
but
I
hope
you
see
the
necessary
evil
that
this
file
is
in
order
to
have
the
language
we
have
today.
I
hope
you
go
forth
to
read
the
rest
of
the
file
and
just
write
more
weird
code.