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

Make inline const work in range patterns #78116

Merged
merged 5 commits into from
Oct 23, 2020

Conversation

spastorino
Copy link
Member

@spastorino spastorino commented Oct 19, 2020

Fixes #78108 which is a follow up of #77124

r? @petrochenkov

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 19, 2020
@camelid camelid added A-patterns Relating to patterns and pattern matching F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) A-parser Area: The parsing of Rust source code to an AST. labels Oct 19, 2020
@petrochenkov
Copy link
Contributor

r=me with additional test cases.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 19, 2020
@spastorino
Copy link
Member Author

@petrochenkov check it out again because the half open ranges solutions seems a bit hacky to me.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 20, 2020
compiler/rustc_ast/src/token.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/pat.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/pat.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/pat.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 20, 2020
@spastorino spastorino force-pushed the inline-const-in-range-pat branch 2 times, most recently from 5ce71b5 to 55c6566 Compare October 20, 2020 22:26
@spastorino spastorino force-pushed the inline-const-in-range-pat branch 2 times, most recently from 5ce71b5 to 55c6566 Compare October 20, 2020 22:33
Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to add some UI check-fail tests for cases like:

match x {
    1 .. const 2 => {}
}

@spastorino
Copy link
Member Author

match x {
    1 .. const 2 => {}
}

It's interesting how this case fails ...

error[E0586]: inclusive range with no end
 --> src/test/ui/inline-const/const-match-pat-fail.rs:5:11
  |
5 |         1 ..= const 2 => {}
  |           ^^^ help: use `..` instead
  |
  = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)

error: expected one of `=>`, `if`, or `|`, found keyword `const`
 --> src/test/ui/inline-const/const-match-pat-fail.rs:5:15
  |
5 |         1 ..= const 2 => {}
  |               ^^^^^ expected one of `=>`, `if`, or `|`

error[E0658]: half-open range patterns are unstable
 --> src/test/ui/inline-const/const-match-pat-fail.rs:5:9
  |
5 |         1 ..= const 2 => {}
  |         ^^^^^
  |
  = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
  = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable

In the parser we are looking for const { not just const so it asummes that it's a half-open range with no end. Unsure what would be ok to do with this case but the error doesn't sound great.
Anyway it's the same that happens if instead of const you use something else like let.

error[E0586]: inclusive range with no end
 --> src/test/ui/inline-const/const-match-pat-fail.rs:5:11
  |
5 |         1 ..= let 2 => {}
  |           ^^^ help: use `..` instead
  |
  = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)

error: expected one of `=>`, `if`, or `|`, found keyword `let`
 --> src/test/ui/inline-const/const-match-pat-fail.rs:5:15
  |
5 |         1 ..= let 2 => {}
  |               ^^^ expected one of `=>`, `if`, or `|`

error[E0658]: half-open range patterns are unstable
 --> src/test/ui/inline-const/const-match-pat-fail.rs:5:9
  |
5 |         1 ..= let 2 => {}
  |         ^^^^^
  |
  = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
  = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable

@camelid
Copy link
Member

camelid commented Oct 20, 2020

In the parser we are looking for const { not just const so it asummes that it's a half-open range with no end. Unsure what would be ok to do with this case but the error doesn't sound great.

I'm trying to work on this in #78168.

@spastorino spastorino removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 21, 2020
@spastorino spastorino added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 21, 2020
@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 21, 2020

r=me after rebasing and squashing commits.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 21, 2020
@spastorino
Copy link
Member Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Oct 22, 2020

📌 Commit 5656a41 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 22, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Oct 22, 2020
…t, r=petrochenkov

Make inline const work in range patterns

Fixes rust-lang#78108 which is a follow up of rust-lang#77124

r? @petrochenkov
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 23, 2020
Rollup of 17 pull requests

Successful merges:

 - rust-lang#77268 (Link to "Contributing to Rust" rather than "Getting Started".)
 - rust-lang#77339 (Implement TryFrom between NonZero types.)
 - rust-lang#77488 (Mark `repr128` as `incomplete_features`)
 - rust-lang#77890 (Fixing escaping to ensure generation of welformed json.)
 - rust-lang#77918 (Cleanup network tests)
 - rust-lang#77920 (Avoid extraneous space between visibility kw and ident for statics)
 - rust-lang#77969 (Doc formating consistency between slice sort and sort_unstable, and big O notation consistency)
 - rust-lang#78098 (Clean up and improve some docs)
 - rust-lang#78116 (Make inline const work in range patterns)
 - rust-lang#78153 (Sync LLVM submodule if it has been initialized)
 - rust-lang#78163 (Clean up lib docs)
 - rust-lang#78169 (Update cargo)
 - rust-lang#78231 (Make closures inherit the parent function's target features)
 - rust-lang#78235 (Explain where the closure return type was inferred)
 - rust-lang#78255 (Reduce diagram mess in 'match arms have incompatible types' error)
 - rust-lang#78263 (Add regression test of issue-77668)
 - rust-lang#78265 (Add some inference-related regression tests about incorrect diagnostics)

Failed merges:

r? `@ghost`
@bors bors merged commit 982c4b3 into rust-lang:master Oct 23, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST. A-patterns Relating to patterns and pattern matching F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A problem with inline_const feature in ranges
6 participants