-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for RFC 554: pattern_parentheses
feature
#51087
Comments
…lexcrichton Ensure every unstable language feature has a tracking issue. Filled in the missing numbers: * `abi_ptx` → #38788 * `generators` → #43122 * `global_allocator` → #27389 Reused existing tracking issues because they were decomposed from a larger feature * `*_target_feature` → #44839 (reusing the old `target_feature` number) * `proc_macros_*` → #38356 (reusing the to-be-stabilized `proc_macros` number) Filed new issues * `exhaustive_patterns` → #51085 * `pattern_parentheses` → #51087 * `wasm_custom_section` and `wasm_import_module` → #51088
Nominating for lang-team discussion. I think that we ought to stabilize this feature. It extends the pattern grammar with parentheses — really not much to say about it. That said, looking about the repo i didn't find many tests. One of my motivations is to address the "precedence fix" of |
(Also I think we should make sure to extend the Rust Reference before stabilizing.) |
@rfcbot fcp merge I would like to move to stabilize this feature. I am going to break my own rules by not providing a stability report that links to tests, but as part of the stabilization PR (or earlier...) we can add some of the tests that I think are missing (or maybe they are there and I did not see them). What is being stabilizedIntroducing the ability to have parenthesized patterns |
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Definitely feels like this needs careful tests, especially about weird macro stuff I don't understand, but if people are fine with doing that as part of stabilization then I'm fine with that too. @rfcbot reviewed |
macro_rules! foo {
($x:pat) => { "pattern" };
($x:expr) => { "expr" };
}
fn main() {
println!("{}", foo!((4)));
} This currently compiles on stable in 1.26 and prints "pattern", so we've already stabilized that this syntax parses as a pattern. I think that for changes like this we should start tracking branches hit during parsing in order to feature gate, rather than traversing the resulting AST, which fails to catch cases like this where |
@cramertj We can probably solve that by moving to a sort of "persistent forest" for caching parsed AST fragments, for both macro invocations, but also the (Note that we can't know the feature gate set before parsing and macro-expanding the crate) |
Right-- I was proposing that we track the set of features used during parsing and macro expansion and only report errors once we had finished and seen that the list of features used wasn't a subset of the features enabled. |
This probably doesn't rise to a full concern, but I think the match (1) { // Warns, as expected
(_) => {} // Doesn't warn, but should for consistency
} https://play.rust-lang.org/?gist=9f08276033eab518cd8055ff148c266a&version=nightly |
The final comment period, with a disposition to merge, as per the review above, is now complete. |
@rust-lang/compiler @petrochenkov Is anyone keen to implement the stability PR for this (or create an issue with mentoring instructions)? It is a factor in one of the edition lints (#51043 (comment)) so is somewhat urgent. |
Triage: no movement since 2018-07-04; cc @rust-lang/compiler |
Mentoring instructionsThis is a straightforward stabilization PR, so you can follow the instructions found in the forge page "So you want to stabilize a feature?". In this case, the feature gate is: |
Also, unused_patterns lint is still not updated; #51087 (comment) |
@scottmcm ah, good catch, although I think it's not a blocker, as we can extend lints after the fact. Regardless, here are some tips for how to update that lint. The lint itself is declared here: rust/src/librustc_lint/unused.rs Lines 258 to 262 in 3bc2ca7
The meat of it is found in the rust/src/librustc_lint/unused.rs Line 326 in 3bc2ca7
As you can see, it checks for various places where a lint would not be needed, such as in the body if an For patterns, I imagine we'll want to do something similar, but adding a That said, I think this is quite a bit harder than the stabilization itself. If the person who handles this issue wants to do it, seems great, but if they are not familiar with the compiler, I think we could leave it out from the first PR, and then move this to a distinct issue to be added at some later time. |
i've been looking for a good way to contribute and this seems like something i could take a look at this weekend but if someone else wants to tackle this ahead of time let me know! -- i will probably skip the lint bit |
@nikomatsakis i followed the forge guide for PR #54497. I've built the compiler locally and run on a test file incorporating the above sample: https://play.rust-lang.org/?gist=c8579523967ed072ea07cac191ee52cd&version=nightly&mode=debug&edition=2015 I ran all of the tests ( Two questions:
This PR doesn't include the lint issue discussed above. |
Filed #54538 for the unused-patterns lint. |
Well, more tests are always good. I see that I did not an absence of tests here. I'm not sure there are any particularly tricky scenarios here, but if you wanted to try to add parenthesis into various existing pattern tests, it seems like it would be good. Any pointers on documentation? Seems like this should be updated: https://doc.rust-lang.org/reference/expressions/match-expr.html, but not sure what else makes sense right now. Good question. I would think we would want to update the grammar on patterns, but I didn't see that one was defined in there. (cc @alercah @Havvy) |
Cc @ehuss |
…ikomatsakis Stabilize pattern_parentheses feature Addresses #51087 . Stabilizes the previously unstable feature `pattern_parentheses` which enables the use of `()` in match patterns.
Removing P-high marker— though I would definitely appreciate some feedback from the @rust-lang/docs folk on what doc if any they feel is needed for this. Seems pretty minor though. |
The reference is updated. We'll also want to update TRPL though, I think. |
Filed in the TRPL repo; closing therefore. |
This tracks the
pattern_parentheses
feature which allows using parenthesis to group patterns.(relevant RFC issue: rust-lang/rfcs#554).
The text was updated successfully, but these errors were encountered: