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

Remove alt check #3101

Closed
brson opened this issue Aug 3, 2012 · 14 comments
Closed

Remove alt check #3101

brson opened this issue Aug 3, 2012 · 14 comments
Labels
A-grammar Area: The grammar of Rust E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Milestone

Comments

@brson
Copy link
Contributor

brson commented Aug 3, 2012

This is an unnecessary corner of the language, the only remaining use of the check keyword. I know I have misexplained the difference between alt and alt check before.

alt check is a bit of an anti-pattern because it:

  • Indicates that enums aren't factored correctly. With case classes we should have more control to prevent this kind of problem.
  • Encourages non-exhaustive matches which are only discovered at runtime.
  • Doesn't provide any documentation about why other cases don't matter.

Which is clearer?

alt check foo {
    bar => baz
}
alt foo {
    bar => baz,
    _ => fail "this shouldn't happen because ..."
}

The first requires explaination. The second says exactly what the fallthrough behavior is, occurs syntactically where the fallthrough behavior occurs, and is more natural to write (once you've written all the cases you intend to cover you then write the fallthrough case instead of going back to the top of the structure and changing it).

@brson
Copy link
Contributor Author

brson commented Aug 3, 2012

There's also no equivalent syntax for _ => { /* fallthrough */ } which is just as common a pattern.

@bblum
Copy link
Contributor

bblum commented Aug 3, 2012

Related #1679.

I strongly favour this change. I argued with @gwillen about this a while ago; my stance was that the language should make it difficult rather than easy to do this sort of thing. I want a language that forces me to write fail "reason" when I've programmed in an anti-pattern.

I weakly favour match partial showing up as sugar for the fallthrough case.

@gwillen
Copy link
Contributor

gwillen commented Aug 3, 2012

@bblum I think I withdraw my defense of alt check. _ => fail is not really that much harder to write, and makes you explain yourself better.

@lkuper
Copy link
Contributor

lkuper commented Aug 3, 2012

+1.

@catamorphism
Copy link
Contributor

+MAXINT

@catamorphism
Copy link
Contributor

I mentioned this to @brson already, but at least a dozen times I've either run into bugs that resulted from an alt check failing, or made an alt check fail as part of changing the compiler. In every one of these cases, it would have been better for programmer morale to see an informative error message. This also means the thesis that we will only use alt check when we really know the match will never fail is simply false.

We've tried having alt check in the language and it's failed. Exhaustive matches for 2012.

@pcwalton
Copy link
Contributor

pcwalton commented Aug 7, 2012

+1 on this change.

@eholk
Copy link
Contributor

eholk commented Aug 7, 2012

+1

@catamorphism
Copy link
Contributor

In the meeting we decided we had consensus to remove this. I volunteer to do so. (Graydon points out that with the macro system, it's easy for someone to write their own alt check macro.)

@ghost ghost assigned catamorphism Aug 7, 2012
@catamorphism
Copy link
Contributor

(I might try diving into macros myself to write a "do nothing in all omitted cases" macro and a "fail with a given message in all omitted cases" macro. How hard can it be?)

@eholk
Copy link
Contributor

eholk commented Aug 7, 2012

The macro shouldn't be too hard, although you may have to duplicate most of the pattern syntax yourself.

See the follow! macro at https://github.com/eholk/rust/blob/pipes/src/test/run-pass/pipe-bank-proto.rs and the select! macro at https://github.com/eholk/rust/blob/pipes/src/test/run-pass/pipe-select-macro.rs for an example of something that's probably close to what you want.

You might be able to get away with just using token trees rather than duplicating the pattern syntax too.

@catamorphism
Copy link
Contributor

I didn't end up doing the macros (could be added later), but otherwise, this is done: 5e22fb9

@bblum
Copy link
Contributor

bblum commented Aug 25, 2012

yessss

@lkuper
Copy link
Contributor

lkuper commented Aug 25, 2012

Hooray!

bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
Simplify multi-lining binop exprs
RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 21, 2023
jaisnan pushed a commit to jaisnan/rust-dev that referenced this issue Jul 29, 2024
We want to run the proofs in the target crate and don't need to build
(or run) the proofs in any of the host crates. This avoids a need to
make available the `kani` crate to any such host crates.

Resolves rust-lang#3101, rust-lang#3238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust 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

7 participants