LWN.net Logo

Rust-lang

Rust-lang

Posted Apr 5, 2013 22:18 UTC (Fri) by HelloWorld (guest, #56129)
In reply to: Rust-lang by jimparis
Parent article: Mozilla and Samsung building a new browser engine

> A runtime warning? It's hardly trivial at compile time when the compiler might not even know if a branch can be taken.
It doesn't matter whether the branch can be taken, the values of both branches are of type (), and it doesn't make sense to store a value of that type in a variable.


(Log in to post comments)

Rust-lang

Posted Apr 5, 2013 22:47 UTC (Fri) by jimparis (subscriber, #38647) [Link]

> It doesn't matter whether the branch can be taken, the values of both branches are of type ()

So imagine a case where both branches are different. Or where the conditional is deep inside a function before the return value finally gets to the assignment. If having a conditional return type () makes sense in some cases and not others, then you can't trivially warn about it.

Rust-lang

Posted Apr 6, 2013 0:26 UTC (Sat) by HelloWorld (guest, #56129) [Link]

> So imagine a case where both branches are different.
That's a type error in itself in most cases. In order for such code to typecheck, the branches' types must have a common supertype. As far as I can see, Rust allows only interfaces to form hierarchies, and I don't know if it's even possible for () to implement interfaces. But even if it is, this situation is going to be so rare that it's not worth losing any sleep over it.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds