Rollup merge of #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`](https://github.com/rust-lang/rust/issues/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](https://github.com/rust-lang/rust/issues/67264) have been implemented, and since #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 https://github.com/rust-lang/rust/issues/56354
This commit is contained in:
Matthias Krüger 2023-12-05 16:08:35 +01:00 committed by GitHub
commit 81b6263dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 86 deletions

View File

@ -158,6 +158,9 @@ declare_features! (
/// Allows using `#[plugin_registrar]` on functions.
(removed, plugin_registrar, "1.54.0", Some(29597), None,
Some("plugins are no longer supported")),
/// Allows exhaustive integer pattern matching with `usize::MAX`/`isize::MIN`/`isize::MAX`.
(removed, precise_pointer_size_matching, "1.32.0", Some(56354), None,
Some("removed in favor of half-open ranges")),
(removed, proc_macro_expr, "1.27.0", Some(54727), None,
Some("subsumed by `#![feature(proc_macro_hygiene)]`")),
(removed, proc_macro_gen, "1.27.0", Some(54727), None,

View File

@ -543,8 +543,6 @@ declare_features! (
(unstable, offset_of_enum, "1.75.0", Some(106655), None),
/// Allows using `#[optimize(X)]`.
(unstable, optimize_attribute, "1.34.0", Some(54882), None),
/// Allows exhaustive integer pattern matching on `usize` and `isize`.
(unstable, precise_pointer_size_matching, "1.32.0", Some(56354), None),
/// Allows macro attributes on expressions, statements and non-inline modules.
(unstable, proc_macro_hygiene, "1.30.0", Some(54727), None),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.

View File

@ -867,12 +867,6 @@ fn report_non_exhaustive_match<'p, 'tcx>(
exhaustively",
));
}
if cx.tcx.sess.is_nightly_build() {
err.help(format!(
"add `#![feature(precise_pointer_size_matching)]` to the crate attributes to \
enable precise `{ty}` matching",
));
}
} else if ty == cx.tcx.types.str_ {
err.note("`&str` cannot be matched exhaustively, so a wildcard `_` is necessary");
} else if cx.is_foreign_non_exhaustive_enum(ty) {

View File

@ -326,8 +326,7 @@ impl IntRange {
/// `NegInfinity..PosInfinity`. In other words, as far as `IntRange` is concerned, there are
/// values before `isize::MIN` and after `usize::MAX`/`isize::MAX`.
/// This is to avoid e.g. `0..(u32::MAX as usize)` from being exhaustive on one architecture and
/// not others. See discussions around the `precise_pointer_size_matching` feature for more
/// details.
/// not others. This was decided in <https://github.com/rust-lang/rfcs/pull/2591>.
///
/// These infinities affect splitting subtly: it is possible to get `NegInfinity..0` and
/// `usize::MAX+1..PosInfinity` in the output. Diagnostics must be careful to handle these
@ -380,7 +379,7 @@ impl IntRange {
/// Whether the range denotes the fictitious values before `isize::MIN` or after
/// `usize::MAX`/`isize::MAX` (see doc of [`IntRange::split`] for why these exist).
pub(crate) fn is_beyond_boundaries<'tcx>(&self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
ty.is_ptr_sized_integral() && !tcx.features().precise_pointer_size_matching && {
ty.is_ptr_sized_integral() && {
// The two invalid ranges are `NegInfinity..isize::MIN` (represented as
// `NegInfinity..0`), and `{u,i}size::MAX+1..PosInfinity`. `to_diagnostic_pat_range_bdy`
// converts `MAX+1` to `PosInfinity`, and we couldn't have `PosInfinity` in `self.lo`
@ -941,11 +940,8 @@ impl ConstructorSet {
}
}
&ty::Int(ity) => {
let range = if ty.is_ptr_sized_integral()
&& !cx.tcx.features().precise_pointer_size_matching
{
// The min/max values of `isize` are not allowed to be observed unless the
// `precise_pointer_size_matching` feature is enabled.
let range = if ty.is_ptr_sized_integral() {
// The min/max values of `isize` are not allowed to be observed.
IntRange { lo: NegInfinity, hi: PosInfinity }
} else {
let bits = Integer::from_int_ty(&cx.tcx, ity).size().bits() as u128;
@ -956,11 +952,8 @@ impl ConstructorSet {
Self::Integers { range_1: range, range_2: None }
}
&ty::Uint(uty) => {
let range = if ty.is_ptr_sized_integral()
&& !cx.tcx.features().precise_pointer_size_matching
{
// The max value of `usize` is not allowed to be observed unless the
// `precise_pointer_size_matching` feature is enabled.
let range = if ty.is_ptr_sized_integral() {
// The max value of `usize` is not allowed to be observed.
let lo = MaybeInfiniteInt::new_finite(cx.tcx, ty, 0);
IntRange { lo, hi: PosInfinity }
} else {

View File

@ -6,7 +6,6 @@ LL | match 0usize {
|
= note: the matched value is of type `usize`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ 0..=usize::MAX => {},
@ -21,7 +20,6 @@ LL | match 0isize {
|
= note: the matched value is of type `isize`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL ~ isize::MIN..=isize::MAX => {},

View File

@ -1,17 +0,0 @@
error[E0004]: non-exhaustive patterns: type `usize` is non-empty
--> $DIR/pointer-sized-int.rs:59:11
|
LL | match 7usize {}
| ^^^^^^
|
= note: the matched value is of type `usize`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
|
LL ~ match 7usize {
LL + _ => todo!(),
LL + }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0004`.

View File

@ -1,12 +1,11 @@
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:14:11
--> $DIR/pointer-sized-int.rs:13:11
|
LL | match 0usize {
| ^^^^^^ pattern `usize::MAX..` not covered
|
= note: the matched value is of type `usize`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ 0..=usize::MAX => {},
@ -14,14 +13,13 @@ LL + usize::MAX.. => todo!()
|
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:19:11
--> $DIR/pointer-sized-int.rs:18:11
|
LL | match 0isize {
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
|
= note: the matched value is of type `isize`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL ~ isize::MIN..=isize::MAX => {},
@ -29,133 +27,124 @@ LL + ..isize::MIN | isize::MAX.. => todo!()
|
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:24:8
--> $DIR/pointer-sized-int.rs:23:8
|
LL | m!(0usize, 0..=usize::MAX);
| ^^^^^^ pattern `usize::MAX..` not covered
|
= note: the matched value is of type `usize`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
| +++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:26:8
--> $DIR/pointer-sized-int.rs:25:8
|
LL | m!(0usize, 0..5 | 5..=usize::MAX);
| ^^^^^^ pattern `usize::MAX..` not covered
|
= note: the matched value is of type `usize`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
| +++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:28:8
--> $DIR/pointer-sized-int.rs:27:8
|
LL | m!(0usize, 0..usize::MAX | usize::MAX);
| ^^^^^^ pattern `usize::MAX..` not covered
|
= note: the matched value is of type `usize`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
| +++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `(usize::MAX.., _)` not covered
--> $DIR/pointer-sized-int.rs:30:8
--> $DIR/pointer-sized-int.rs:29:8
|
LL | m!((0usize, true), (0..5, true) | (5..=usize::MAX, true) | (0..=usize::MAX, false));
| ^^^^^^^^^^^^^^ pattern `(usize::MAX.., _)` not covered
|
= note: the matched value is of type `(usize, bool)`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL | match $s { $($t)+ => {}, (usize::MAX.., _) => todo!() }
| ++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:39:8
--> $DIR/pointer-sized-int.rs:38:8
|
LL | m!(0isize, isize::MIN..=isize::MAX);
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
|
= note: the matched value is of type `isize`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
| ++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:41:8
--> $DIR/pointer-sized-int.rs:40:8
|
LL | m!(0isize, isize::MIN..5 | 5..=isize::MAX);
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
|
= note: the matched value is of type `isize`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
| ++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:43:8
--> $DIR/pointer-sized-int.rs:42:8
|
LL | m!(0isize, isize::MIN..=-1 | 0 | 1..=isize::MAX);
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
|
= note: the matched value is of type `isize`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
| ++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
--> $DIR/pointer-sized-int.rs:45:8
--> $DIR/pointer-sized-int.rs:44:8
|
LL | m!(0isize, isize::MIN..isize::MAX | isize::MAX);
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
|
= note: the matched value is of type `isize`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
| ++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `(..isize::MIN, _)` and `(isize::MAX.., _)` not covered
--> $DIR/pointer-sized-int.rs:48:9
--> $DIR/pointer-sized-int.rs:47:9
|
LL | (0isize, true),
| ^^^^^^^^^^^^^^ patterns `(..isize::MIN, _)` and `(isize::MAX.., _)` not covered
|
= note: the matched value is of type `(isize, bool)`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL | match $s { $($t)+ => {}, (..isize::MIN, _) | (isize::MAX.., _) => todo!() }
| ++++++++++++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: type `usize` is non-empty
--> $DIR/pointer-sized-int.rs:59:11
--> $DIR/pointer-sized-int.rs:58:11
|
LL | match 7usize {}
| ^^^^^^

View File

@ -1,6 +1,5 @@
// revisions: allow deny
// revisions: deny
#![feature(exclusive_range_pattern)]
#![cfg_attr(allow, feature(precise_pointer_size_matching))]
#![allow(overlapping_range_endpoints)]
macro_rules! m {
@ -12,23 +11,23 @@ macro_rules! m {
#[rustfmt::skip]
fn main() {
match 0usize {
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
0..=usize::MAX => {}
}
match 0isize {
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
isize::MIN..=isize::MAX => {}
}
m!(0usize, 0..=usize::MAX);
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!(0usize, 0..5 | 5..=usize::MAX);
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!(0usize, 0..usize::MAX | usize::MAX);
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!((0usize, true), (0..5, true) | (5..=usize::MAX, true) | (0..=usize::MAX, false));
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!(0usize, 0..);
m!(0usize, 0..5 | 5..);
@ -37,18 +36,18 @@ fn main() {
m!(0usize, 0..=usize::MAX | usize::MAX..);
m!(0isize, isize::MIN..=isize::MAX);
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!(0isize, isize::MIN..5 | 5..=isize::MAX);
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!(0isize, isize::MIN..=-1 | 0 | 1..=isize::MAX);
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!(0isize, isize::MIN..isize::MAX | isize::MAX);
//[deny]~^ ERROR non-exhaustive patterns
//~^ ERROR non-exhaustive patterns
m!(
(0isize, true),
(isize::MIN..5, true) | (5..=isize::MAX, true) | (isize::MIN..=isize::MAX, false)
);
//[deny]~^^^ ERROR non-exhaustive patterns
//~^^^ ERROR non-exhaustive patterns
m!(0isize, ..0 | 0..);
m!(0isize, ..5 | 5..);

View File

@ -6,7 +6,6 @@ LL | match 0usize {
|
= note: the matched value is of type `usize`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ 0..=usize::MAX => {},
@ -21,7 +20,6 @@ LL | match 0isize {
|
= note: the matched value is of type `isize`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL ~ isize::MIN..=isize::MAX => {},

View File

@ -6,7 +6,6 @@ LL | match 0 {
|
= note: the matched value is of type `usize`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ 1..=usize::MAX => (),
@ -21,7 +20,6 @@ LL | match (0usize, 0usize) {
|
= note: the matched value is of type `(usize, usize)`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ (1..=usize::MAX, 1..=usize::MAX) => (),
@ -36,7 +34,6 @@ LL | match (0isize, 0usize) {
|
= note: the matched value is of type `(isize, usize)`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL ~ (isize::MIN..=isize::MAX, 1..=usize::MAX) => (),
@ -74,7 +71,6 @@ note: `Option<usize>` defined here
= note: not covered
= note: the matched value is of type `Option<usize>`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ None => (),
@ -98,7 +94,6 @@ note: `Option<Option<Option<usize>>>` defined here
= note: not covered
= note: the matched value is of type `Option<Option<Option<usize>>>`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ None => (),
@ -118,7 +113,6 @@ LL | struct A<T> {
| ^
= note: the matched value is of type `A<usize>`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ A { a: 1..=usize::MAX } => (),
@ -138,7 +132,6 @@ LL | struct B<T, U>(T, U);
| ^
= note: the matched value is of type `B<isize, usize>`
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
LL ~ B(isize::MIN..=isize::MAX, 1..=usize::MAX) => (),
@ -158,7 +151,6 @@ LL | struct B<T, U>(T, U);
| ^
= note: the matched value is of type `B<isize, usize>`
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ B(_, 1..=usize::MAX) => (),