7 ms·
No you don’t need coercion. You only need polymorphism. The type of `panic!()` could be an arbitrary U, which unifies just fine with the type T here. Generally
by kccqzy 4d ago
No you don’t need coercion. You only need polymorphism. The type of `panic!()` could be an arbitrary U, which unifies just fine with the type T here.
Generally languages with such polymorphism have a never type only because they don’t also support impredicative polymorphism.
- kibwen 4d agoAnd then once you have `fn foo<T>() -> T`, what do you write in the body that allows it to typecheck?
- kccqzy 4d agoYou still write `panic!()`. It type checks using polymorphism only, without any coercions.
- kibwen 3d agoBut `panic!()` is just a macro invocation that needs to expand to something, and the question here is what that something ought to be in order to produce a valid program. Currently it expands to this: https://github.com/rust-lang/rust/blob/98fd715edd3a0a5aa8f2041d7e20a3143b0fc0d3/library/core/src/panicking.rs#L138 https://github.com/rust-lang/rust/blob/98fd715edd3a0a5aa8f20... , which is a function with a return type of `!`, which has indicated a diverging function since long before Rust even considered having a first-class never type.
- kccqzy 3d agoRight. And the whole discussion boils down to, why can’t this function return type be polymorphic in the first place? This avoids the never type, the coercions from the never type, and all the issues caused by that described in the article.