logoalt Hacker News

kccqzyyesterday at 10:02 PM3 repliesview on HN

The lesson here is that implicit conversions are bad. The never type itself having implicit conversions to other types is bad enough (even though such coercions are logically valid: “ex falso quodlibet” they should be explicit), but having a fallback type when type inference doesn’t have enough information to produce a type is even worse. Rust is famous for not even having implicit numeric coercions (say from i8 to i32) but it seems like a shortsighted decision to allow implicit coercions here.


Replies

jadenPeteyesterday at 10:17 PM

Why is it bad? Implicit integer conversions are generally bad because they can produce unexpected behavior at runtime and obstruct what’s really happening, but that doesn’t seem to be what’s happening here.

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.

show 2 replies
cipherjimyesterday at 11:35 PM

With ! the implicit conversion happens at compile time, never at runtime.

It cannot by definition happen at runtime because the never type has no values and thus cannot be constructed under any circumstances.

Any compile time coercions that occur would convert types (or generics args of types) to !

I find it difficult to imagine any situation where that would result in a working program - only if the coerced types or references to coerced generics were not even used would it compile.

echelonyesterday at 10:39 PM

We should be able to set at a crate level whether our code can compile with panics, implicit conversions, etc. And we should be able to blacklist dependencies and transitive dependencies that do these things. We should be able to advertise a crate's safety and attention to detail.

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.

show 1 reply