Skip to content

Allow unreachable patterns in some form #18077

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

Closed
mahkoh opened this issue Oct 15, 2014 · 7 comments
Closed

Allow unreachable patterns in some form #18077

mahkoh opened this issue Oct 15, 2014 · 7 comments

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Oct 15, 2014

A pattern should not be unreachable if the user cannot know that it's unreachable. E.g.

use X::{A, B};

match 1u {
    A | B => { },
    _ => { },
}

should never be an error even if A == B.

@mahkoh
Copy link
Contributor Author

mahkoh commented Oct 15, 2014

The current status implies that changing a public constant is an API breaking semver change.

@ghost
Copy link

ghost commented Oct 15, 2014

The current status implies that changing a public constant is an API breaking semver change.

This is true. However, constants in patterns are not the only scenario where that can happen. The following example demonstrates how that can occur in a different situation where the values are evaluated at compile time.

use X::{A, B};

fn f() -> [uint, ..A] {
    unreachable!()
}

fn main() {
    let x: [uint, ..B] = f();
}

I am going to close this issue as a dupe of #4112.

In any case, a change of this type would warrant an RFC so if you are interested in pursuing this idea further and submitting a concrete proposal, the RFC process is described here: https://github.com/rust-lang/rfcs#what-the-process-is. Thanks!

@ghost ghost closed this as completed Oct 15, 2014
@reem
Copy link
Contributor

reem commented Oct 15, 2014

@mahkoh I can't imagine that changing a public constant is ever not an API breaking semver change.

@mahkoh
Copy link
Contributor Author

mahkoh commented Oct 15, 2014

@reem: I'm sure your POSIX compatible C program will compile just fine on all platforms even if the error constants EAGAIN and friends aren't the same everywhere.

@mahkoh
Copy link
Contributor Author

mahkoh commented Oct 15, 2014

@jakub- : Your example is not quite the same. In my example above I treat A and B as two constants whose value is unknown or doesn't matter to me. Naturally I cannot assign an array of size A to an array of size B under these conditions. But if the implementation ever changes from A != B to A == B, then the match will break anyway.

@reem
Copy link
Contributor

reem commented Oct 15, 2014

@mahkoh Not if I have an assertion about the values of those constants. I don't think that this worry is without merit, but we should also recognize that changing the value of a constant is a breaking change in 99% of cases. Additionally, these sorts of things should usually be implemented as enums rather than constants.

@ghost
Copy link

ghost commented Oct 16, 2014

@mahkoh Yeah, that was a poor example. Here's another one, though:

trait MyTrait {}
impl MyTrait for [uint, ..A] {}
impl MyTrait for [uint, ..B] {}

This will fail to compile if A == B as that'd mean MyTrait being implemented twice for the same type.

My general point was that changing the value of a constant in a program may indeed change the outcome of typechecking that program if said constant appears in a type.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants