Stabilizing Rust's Never Type

(lwn.net)

57 points | by cjd8 3 days ago ago

2 comments

  • xg15 2 minutes ago

    > After this change (and on the 2024 edition), the compiler assumes that T should be !, which doesn't implement Default, and therefore causes a compilation error.

    If ! can coerce to every type, why not treat it as if it implemented every trait too?

  • epolanski 5 minutes ago

    The never type seems very useful in various languages to either signal that a branch can never happen (the example of string -> bytestring never erroring) or to mark that a function will never return a value (and thus control) to the caller.

    A simple TypeScript example:

    const forever = (): never => { while (true) { // whatever } }