Advertisement
Advertisement
⚡ Community Insights
Discussion Sentiment
36% Positive
Analyzed from 816 words in the discussion.
Trending Topics
#type#never#rust#should#implicit#here#bad#more#conversions#coercions
Discussion Sentiment
Analyzed from 816 words in the discussion.
Trending Topics
Discussion (17 Comments)Read Original on HackerNews
Never is a standard type in many languages and is at the bottom of the type hierarchy because it’s a subtype of every type. Never isn’t implicitly converted any more than `&’a A` is “implicitly converted” into a `&’b B`, where `’a` subsumes `’b`. There’s no runtime conversion because there will never be an instance of never—it represents the value of a computation that never completes by definition.
I think what you mean to say is that implicit runtime conversions are bad, not that all subtyping is bad.
Higher level application code can benefit from this, but core libraries should forbid this statically and be prevented from even compiling or being imported should these things be enabled.
We should be able to filter crates.io by these properties, and force our own projects to abide by them.
I want nopanic, nocoerscion, maxdependencydepth, rustonly, nolinking, etc. flags.
If ! can coerce to every type, why not treat it as if it implemented every trait too?
So this would risk turning a compile-time error into a runtime error.
"When is never?"
https://youtube.com/watch?v=3jM4cnEVrLc
I just checked, my main side project only has less than 10 things that return never. `-> Never` reads even better, imo.
And if you'd like to write `-> Never`, the nice thing about being a first-class type is that you can now just do that if you'd like, via a standard type alias: `type Never = !;`.
Prior to this change most Rust developers would never have cause to ever use `!` for any reason. The only stable way to do so would be to specify the quote-unquote "return type" of divergent functions, which Rust has supported via this special-cased syntax since prehistoric days, before even Mozilla got involved. You can see it in the oldest capture of the tutorial from Jan 2012: https://web.archive.org/web/20120109041112/http://www.rust-l...
So when it came time to elevate `!` from being a special-cased return type to being a fully-fledged type, it was only natural to reuse this syntax. However, I tend to agree that, because we call it "the never type" in casual conversation, the most natural thing to do would be to just have a type alias called `Never` that we could encourage people to use instead. But that would be a perfectly backwards-compatible change that could be made at any point (as proven by the fact that the stopgap and long-stable `Infallible` type is becoming just such a type).
A simple TypeScript example:
const forever = (): never => { while (true) { // whatever } }