Hi there.
There’s an RFC which promotes !
to a type, so it will be possible to write, e. g.
let _: ! = unreachable!();
I’d like to propose
- reserve
never
keyword (or soft keyword, or lang item) for the 2018 epoch - (or
nothing
)
Remaining items are not critical while RFC 1216 is not ready:
- use
never
keyword for the unreachable type - do not allow
!
anywhere except in return type - allow
!
in return type for backward compatibility
Why keyword
The principle is that punctuation should be used for the most frequently used language constructs, and keywords for less frequently used.
I’ve counted in rust sources, it has only 160 usages of !
as type (including tests)
rg -F -- '-> ! {' | wc -l
For comparison, Option
is used 15703 times. str
is used 10309 times.
Personally, I have a couple of better (that unreachable type) use cases for !
, e. g.
-
!
forunwrap
, e. g.file.write()!
to be equivalent offile.write().unwrap()
, which would be useful in scripts, e. g.build.rs
-
!
for force matching, e. g.let! Ok(count) = file.write();
to be equivalent of panicing of function returns other variant thanOk(_)
But concrete applications of !
are not important right now, my point is that we shouldn’t stabilize new use of !
, because it will be hard to unstabilize it and reuse !
for something different later.
RFC 1216
Technically, this alternative is mentioned in RFC 1216.
I’m raising this issue now because if never
should be a keyword, it should be reserved before epoch 2018, and the decision whether the unreachable type should be !
or a keyword could be done later.