You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so it should be pretty simple - if there are no arms, then it returns !. if there are no arms when there should be arms, then it's up to the exhaustiveness checker to report an error
The best documentation I could find was a blog post by Niko. Also take a look at the linked RFC. I think this is something missing in the reference.
I think this paragraph from the RFC explains it best:
let foo:&'static str = match x {};
Reading this, it may be tempting to ask the question "what is the value of foo then?". Remember that this depends on the value of x. As there are no possible values of x it's a meaningless question and besides, the fact that x has type Never gives us a static guarantee that the match block will never be executed.
Because the scrutinee is an uninhabited type (which the never type is), it can never be created. So this match can never be executed. So the type of the expression is ! = never.
Summary
Match expressions with no arms should give a value of type
!
Reproducer
I tried this code:
Does the code make use of any (1.49) nightly feature ?
Godbolt link
link
Actual behavior
Expected behavior
No error
GCC Version
GCCRS master on godbolt
The text was updated successfully, but these errors were encountered: