Comment

Comment by jadenPete

Here’s another example:

  fn f<T>() -> T {
    loop {
      println!(“Looping”);
    }
  }
This won’t compile. How do you express to the compiler that this is correct (because the function never completes) without a never type?

Rust also doesn’t support generic function types, so a callback function returning `!` is possible, whereas one accepting a type argument and returning that type is not. You could do something clever with traits, but that requires extra work.

A lot of these things are achievable without `!`, but the compiler still needs that type internally and it pieces so nicely into the type system that I don’t see the point of bending over backwards to avoid it.

parent jadenPete 1 month ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton