-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Comments
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! |
@mahkoh I can't imagine that changing a public constant is ever not an API breaking semver change. |
@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. |
@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. |
@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. |
@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. |
A pattern should not be unreachable if the user cannot know that it's unreachable. E.g.
should never be an error even if A == B.
The text was updated successfully, but these errors were encountered: