|
|
Log in / Subscribe / Register

MISRA

MISRA

Posted Sep 19, 2021 18:12 UTC (Sun) by tialaramex (subscriber, #21167)
In reply to: MISRA by NYKevin
Parent article: Conill: The long-term consequences of maintainers’ actions

Technically match is actually an expression, and so it's logically _obliged_ to follow only one arm because the expression obviously only has one value, and in fact the values in each arm must be type compatible, the Rust compiler will conclude that whichever type is compatible with all the arms is in fact the type of the expression, if there is no suitable type that's an error.

https://play.rust-lang.org/?version=stable&mode=debug...

The compiler points out that two of the arms are clearly integers while another is an &str (in this case a string literal).

In many cases the idiomatic Rust way to express what you wanted actually does involve values from each arm, but of course it is possible for your match to be full of procedural code in which case those values are just the empty tuple -- or for it to have statements which outright leave the match (such as "return" or "break") and these are in fact type compatible with anything.


to post comments


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