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

Remove the precise_pointer_size_matching feature gate #118598

Merged

Conversation

Nadrieril
Copy link
Member

@Nadrieril Nadrieril commented Dec 4, 2023

usize and isize are special for pattern matching because their range might depend on the platform. To make code portable across platforms, the following is never considered exhaustive:

let x: usize = ...;
match x {
    0..=18446744073709551615 => {}
}

Because of how rust handles constants, this also unfortunately counts 0..=usize::MAX as non-exhaustive. The precise_pointer_size_matching feature gate was introduced both for this convenience and for the possibility that the lang team could decide to allow the above.

Since then, half-open range patterns have been implemented, and since #116692 they correctly support usize/isize:

match 0usize { // exhaustive!
    0..5 => {}
    5.. => {}
}

I believe this subsumes all the use cases of the feature gate. Moreover no attempt has been made to stabilize it in the 5 years of its existence. I therefore propose we retire this feature gate.

Closes #56354

@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2023

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 4, 2023
@rust-log-analyzer

This comment has been minimized.

@Nadrieril Nadrieril force-pushed the remove_precise_pointer_size_matching branch from f3ff8e9 to 5e470db Compare December 4, 2023 10:56
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

LGTM, one suggestion, but otherwise r=me

@davidtwco
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 5, 2023

📌 Commit 5e470db has been approved by davidtwco

It is now in the queue for this repository.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 5, 2023
@Nadrieril
Copy link
Member Author

Nice, thank you!

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#117922 (Tweak unclosed generics errors)
 - rust-lang#118471 (Fix typos in README.md)
 - rust-lang#118594 (Remove mention of rust to make the error message generic.)
 - rust-lang#118598 (Remove the `precise_pointer_size_matching` feature gate)
 - rust-lang#118606 (Fix `x` not to quit after `x` prints `settings.json`)
 - rust-lang#118608 (Use default params until effects in desugaring)
 - rust-lang#118614 (Update books)
 - rust-lang#118637 (rustc_symbol_mangling,rustc_interface,rustc_driver_impl: Enforce `rustc::potential_query_instability` lint)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 81b6263 into rust-lang:master Dec 5, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 5, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2023
Rollup merge of rust-lang#118598 - Nadrieril:remove_precise_pointer_size_matching, r=davidtwco

Remove the `precise_pointer_size_matching` feature gate

`usize` and `isize` are special for pattern matching because their range might depend on the platform. To make code portable across platforms, the following is never considered exhaustive:
```rust
let x: usize = ...;
match x {
    0..=18446744073709551615 => {}
}
```
Because of how rust handles constants, this also unfortunately counts `0..=usize::MAX` as non-exhaustive. The [`precise_pointer_size_matching`](rust-lang#56354) feature gate was introduced both for this convenience and for the possibility that the lang team could decide to allow the above.

Since then, [half-open range patterns](rust-lang#67264) have been implemented, and since rust-lang#116692 they correctly support `usize`/`isize`:
```rust
match 0usize { // exhaustive!
    0..5 => {}
    5.. => {}
}
```
I believe this subsumes all the use cases of the feature gate. Moreover no attempt has been made to stabilize it in the 5 years of its existence. I therefore propose we retire this feature gate.

Closes rust-lang#56354
@Nadrieril Nadrieril deleted the remove_precise_pointer_size_matching branch December 8, 2023 23:41
@Nadrieril Nadrieril added the A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns label Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for RFC 2591: precise pattern matching on pointer size types
6 participants