|
|
Log in / Subscribe / Register

Never traits

Never traits

Posted Sep 11, 2026 5:39 UTC (Fri) by micka (subscriber, #38720)
In reply to: Never traits by tsavola
Parent article: Stabilizing Rust's never type

For Default, you need to provide one value, and you can’t do that for !.


to post comments

Never traits

Posted Sep 11, 2026 5:50 UTC (Fri) by tsavola (subscriber, #37605) [Link] (2 responses)

Yes, but with ! that code path is never reached. The compiler could say that it can, because it never has to.

Never traits

Posted Sep 11, 2026 6:57 UTC (Fri) by taladar (subscriber, #68407) [Link] (1 responses)

But that is not how traits work in Rust. What you suggest would be true if all traits just had their types appear in parameter position in the methods they implement but traits like Default have them appear only in return type position where you absolutely have to come up with a value if someone calls <! as Default>::default()

Never traits

Posted Sep 11, 2026 7:17 UTC (Fri) by tsavola (subscriber, #37605) [Link]

Okay, I see.


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