-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Restrict constants in patterns #32199
Merged
bors
merged 10 commits into
rust-lang:master
from
nikomatsakis:limiting-constants-in-patterns-2
Mar 26, 2016
Merged
Restrict constants in patterns #32199
bors
merged 10 commits into
rust-lang:master
from
nikomatsakis:limiting-constants-in-patterns-2
Mar 26, 2016
Commits on Mar 25, 2016
-
Configuration menu - View commit details
-
Copy full SHA for 5bc2868 - Browse repository at this point
Copy the full SHA 5bc2868View commit details -
modify #[deriving(Eq)] to emit #[structural_match]
to careful use of the span from deriving, we can permit it in stable code if it derives from deriving (not-even-a-pun intended)
Configuration menu - View commit details
-
Copy full SHA for 99c2a6b - Browse repository at this point
Copy the full SHA 99c2a6bView commit details -
do not overwrite spans as eagerly
this was required to preserve the span from the #[structural_match] attribute -- but honestly I am not 100% sure if it makes sense.
Configuration menu - View commit details
-
Copy full SHA for 05baf64 - Browse repository at this point
Copy the full SHA 05baf64View commit details -
issue a future-compat lint for constants of invalid type
This is a [breaking-change]: according to RFC rust-lang#1445, constants used as patterns must be of a type that *derives* `Eq`. If you encounter a problem, you are most likely using a constant in an expression where the type of the constant is some struct that does not currently implement `Eq`. Something like the following: ```rust struct SomeType { ... } const SOME_CONST: SomeType = ...; match foo { SOME_CONST => ... } ``` The easiest and most future compatible fix is to annotate the type in question with `#[derive(Eq)]` (note that merely *implementing* `Eq` is not enough, it must be *derived*): ```rust struct SomeType { ... } const SOME_CONST: SomeType = ...; match foo { SOME_CONST => ... } ``` Another good option is to rewrite the match arm to use an `if` condition (this is also particularly good for floating point types, which implement `PartialEq` but not `Eq`): ```rust match foo { c if c == SOME_CONST => ... } ``` Finally, a third alternative is to tag the type with `#[structural_match]`; but this is not recommended, as the attribute is never expected to be stabilized. Please see RFC rust-lang#1445 for more details.
Configuration menu - View commit details
-
Copy full SHA for f69eb8e - Browse repository at this point
Copy the full SHA f69eb8eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 73b4f06 - Browse repository at this point
Copy the full SHA 73b4f06View commit details -
Configuration menu - View commit details
-
Copy full SHA for 56ebf2b - Browse repository at this point
Copy the full SHA 56ebf2bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7f661ec - Browse repository at this point
Copy the full SHA 7f661ecView commit details -
Configuration menu - View commit details
-
Copy full SHA for 93e4443 - Browse repository at this point
Copy the full SHA 93e4443View commit details -
Configuration menu - View commit details
-
Copy full SHA for 944dc4a - Browse repository at this point
Copy the full SHA 944dc4aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 2536ae5 - Browse repository at this point
Copy the full SHA 2536ae5View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.