News for hackers. Stuff that matters.
Re:Weird Expressions in Rust by throwawaymaths on Friday June 27, 2025 @01:52PM (#44398822)
its not just that some things you would usually think are control flow are expressions, its also that there are unusual rules around coercing the `noreturn` type.
Re:Weird Expressions in Rust by tialaramex on Friday June 27, 2025 @08:59PM (#44401592)
The only "unusual" rule here is that Rust offers the zero type addition, but does not provide the (much more complicated) other type additions

So Rust does have: String + ! = String

But Rust doesn't have: String + i32 = Either<String,i32>

Note that the never type ! isn't special here, Rust will also cheerfully: String + Infallible = String or if you were to define your own empty type like so:

    enum MyEmptyType {} // MyEmptyType has no possible values
Now under type arithmetic String + MyEmptyType = String and indeed that works in Rust.

Edited: Syntax fix