Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static exhaustiveness checking #352

Closed
graydon opened this issue May 5, 2011 · 11 comments
Closed

static exhaustiveness checking #352

graydon opened this issue May 5, 2011 · 11 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@graydon
Copy link
Contributor

graydon commented May 5, 2011

Currently a non-exhaustive match is silently compiled and turns into a runtime fault if it hits the not-handled case. It'd be nice to at least have a warning, or perhaps strict checking, on non-exhaustive matches.

@ghost ghost assigned lkuper May 5, 2011
@ghost ghost assigned lkuper Aug 11, 2011
@rpearl
Copy link

rpearl commented Nov 8, 2011

This seems like a reasonable way learn my way around the rustc codebase. If I have a chance in the next week or so I'll look at this.

@ghost ghost assigned catamorphism Jan 24, 2012
@catamorphism
Copy link
Contributor

Taking this. If someone else is dying to do it, let me know...

@rpearl
Copy link

rpearl commented Jan 24, 2012

Yeah, I sadly don't have time for this, even though it looked interesting. Have fun.

@nikomatsakis
Copy link
Contributor

I want this.

@catamorphism
Copy link
Contributor

Working on it right now!

@catamorphism
Copy link
Contributor

I have the code finished, which entailed making every non-exhaustive case in rustc and libraries exhaustive.

I won't check it in just yet because there were objections to it in a different issue discussion. With hope, we can discuss this tomorrow. My opinion: it's really important to be able to distinguish, immediately, between "I left out this case because I believe I can prove it's statically impossible to reach it" and "I forgot to include this case". If we don't have that, it's going to get really embarrassing. Just look at some of the experience reports from the darcs people about how many of the errors involved use of Maybe::fromJust (the Haskell equivalent of option::get) without proving that it wouldn't fail with a non-exhaustive match.

@catamorphism
Copy link
Contributor

(also, when I was making alts exhaustive, it was almost never obvious to me why the omitted cases were unreachable. IMO, it's only excusable to omit cases if one either documents why, if the invariant that makes it safe is so obvious that someone can tell from glancing at the code that it's true.)

@kud1ing
Copy link

kud1ing commented Jan 31, 2012

"I left out this case because I believe I can prove it's statically impossible to reach it":

I think "impossible" situations could be documented with an assertion and an explanation quite nicely like: _ { assert(false); } // will never happen, because XYZ

@catamorphism
Copy link
Contributor

@Lenny222 That's at least the minimum we could strive for, again IMO. Ideally, the type system will eventually be precise enough that we can get rid of all but a few of "assert(false)"s. (Hopefully at least a 'fail "helpful message"' instead of assert(false).)

@kud1ing
Copy link

kud1ing commented Jan 31, 2012

Agreed.

@catamorphism
Copy link
Contributor

Fixed in fba35e1 -- also see #1679 for some discussion of features that could help reduce the need for redundant cases. In the meeting today, we also discussed using attributes to mark particular alt expressions as non-exhaustive, but that's for future work.

marijnh added a commit that referenced this issue Feb 15, 2012
Issue #352
Closes #1720

The old checker would happily accept things like 'alt x { @some(a) { a } }'.
It now properly descends into patterns, checks exhaustiveness of booleans,
and complains when number/string patterns aren't exhaustive.
kazcw pushed a commit to kazcw/rust that referenced this issue Oct 23, 2018
)

Better error messages for target-feature detection macros
dlrobertson pushed a commit to dlrobertson/rust that referenced this issue Nov 29, 2018
General attribute docs improvements
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Oct 26, 2020
ZuseZ4 pushed a commit to EnzymeAD/rust that referenced this issue Mar 7, 2023
antoyo added a commit to antoyo/rust that referenced this issue Oct 26, 2023
Fix #[inline(always)] attribute and support unsigned comparison for signed integers
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
…t-lang#352)

Use vtable index passed at call site to resolve functions

Co-authored-by: Daniel Schwartz-Narbonne <danielsn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

6 participants