A pull request has been done with a new test for the Rust compiler. It verifies that a strange line can compile:
fn main() {
let val = !((|(..):(_,_),__@_|__)((&*"\\",'@')/**/,{})=={&[..=..][..];})//
;
assert!(!val);
}
What does this line do exactly?
Let's break it down! First, I reformatted the line to somewhat increase "readability".
let val = !(
(
|(..): (_, _), __@_| __
)(
(
&*"\\",
'@'
) /**/,
{}
)
==
{
&[..=..][..];
}
)//
;
It starts with let val =
and ends with //<newline>;
. So it's a simple let-binding of the form let val = ⟨v⟩;
. Let's discuss what ⟨v⟩
does:
!( ⟨_⟩ )
==
: ⟨lhs⟩ == ⟨rhs⟩
( ⟨closure⟩ )( ⟨args⟩ )
|⟨first_param⟩, ⟨second_param⟩| ⟨body⟩
(..): (_, _)
. This parameter has a type annotation (_, _)
meaning that it is a 2-tuple. The pattern (where normally, you would find a single name) is (..)
which means: a tuple, but ignore all elements of it.__@_
. This is a pattern usually known from match bindings: name @ pattern
. So the actual pattern is _
(which doesn't bind anything) and the value is bound via @
to the name __
(two underscores, which is a kind of valid identifier).__
. This is just the identifier which we bound the second parameter to. So the closure is basically equivalent to |_, x| x
./**/
in between: ⟨first_arg⟩/**/, ⟨second_arg⟩
(&*"\\", '@')
. This is simply a 2-tuple where the first element is a string containing a backslash and the second is the char '@'
. The &*
for the first element cancels out.{}
. This is an empty block which has the type ()
. So as second argument, a unit is passed.{ ⟨stmt⟩; }
. Note that this is a statement, with a semicolon. This means the result is not returned from the block. Instead the block returns ()
just as the empty block {}
.
{ &⟨collection⟩[⟨index⟩] }
.
[..=..]
. This is an array with one element. The element is ..= ..
which is a RangeToInclusive
where end
of the range is the RangeFull
written ..
. ..
. This is just the RangeFull
again. So in summary: we compare the result of calling a closure to a braced block which evaluates to ()
. The closure is basically |_, x| x
and the second argument we pass to it is {}
(which evaluates to ()
), so the whole closure calling expression evaluates to ()
.
This means the whole thing is equivalent to:
let val = !( () == () );
, which is equivalent to:let val = !( true );
, which is equivalent to:let val = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With