reference icon indicating copy to clipboard operation
reference copied to clipboard

Exhaustivity checking on match patterns is not defined

Open alercah opened this issue 5 years ago • 3 comments
trafficstars

I can't find any mention of exhaustivity checking on the Match expressions page.

alercah avatar Apr 16 '20 03:04 alercah

I believe that it must be a section talking of exhaustivity stating that a match expression must have either one irrefutable pattern or one or more refutable patterns that contain all the values the scrutinee can be if the type it's not marked with non_exhaustive.

Also note that the last attribute defines well what kind of pattern matching are allowed in a non-exhaustive type but only implicitly what it's accepted outside one of these types. It's particularly unclear with enums saying "When pattern matching on a non-exhaustive enum, matching on a variant does not contribute towards the exhaustiveness of the arms." when it never talks of exhaustiveness before so the reader have to guess that an enum being exhausted refers to all the variants being matched.

IronThread avatar Nov 27 '20 17:11 IronThread

Note: https://github.com/rust-lang/rust/pull/122792 made some recent changes for exhaustiveness.

ehuss avatar Aug 10 '24 16:08 ehuss

And indeed I could not find anywhere in the reference that talked about exhaustiveness when I made the stabilization PR. The only place that mentioned it a bit was the nomicon.

Nadrieril avatar Aug 10 '24 17:08 Nadrieril