Skip to content

Commit 0a6f57d

Browse files
authored
Unrolled build for rust-lang#118598
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
2 parents 8a7b203 + 5e470db commit 0a6f57d

10 files changed

+33
-86
lines changed

compiler/rustc_feature/src/removed.rs

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

compiler/rustc_feature/src/unstable.rs

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

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

-6
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,6 @@ fn report_non_exhaustive_match<'p, 'tcx>(
867867
exhaustively",
868868
));
869869
}
870-
if cx.tcx.sess.is_nightly_build() {
871-
err.help(format!(
872-
"add `#![feature(precise_pointer_size_matching)]` to the crate attributes to \
873-
enable precise `{ty}` matching",
874-
));
875-
}
876870
} else if ty == cx.tcx.types.str_ {
877871
err.note("`&str` cannot be matched exhaustively, so a wildcard `_` is necessary");
878872
} else if cx.is_foreign_non_exhaustive_enum(ty) {

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ impl IntRange {
326326
/// `NegInfinity..PosInfinity`. In other words, as far as `IntRange` is concerned, there are
327327
/// values before `isize::MIN` and after `usize::MAX`/`isize::MAX`.
328328
/// This is to avoid e.g. `0..(u32::MAX as usize)` from being exhaustive on one architecture and
329-
/// not others. See discussions around the `precise_pointer_size_matching` feature for more
330-
/// details.
329+
/// not others. This was decided in <https://github.com/rust-lang/rfcs/pull/2591>.
331330
///
332331
/// These infinities affect splitting subtly: it is possible to get `NegInfinity..0` and
333332
/// `usize::MAX+1..PosInfinity` in the output. Diagnostics must be careful to handle these
@@ -380,7 +379,7 @@ impl IntRange {
380379
/// Whether the range denotes the fictitious values before `isize::MIN` or after
381380
/// `usize::MAX`/`isize::MAX` (see doc of [`IntRange::split`] for why these exist).
382381
pub(crate) fn is_beyond_boundaries<'tcx>(&self, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
383-
ty.is_ptr_sized_integral() && !tcx.features().precise_pointer_size_matching && {
382+
ty.is_ptr_sized_integral() && {
384383
// The two invalid ranges are `NegInfinity..isize::MIN` (represented as
385384
// `NegInfinity..0`), and `{u,i}size::MAX+1..PosInfinity`. `to_diagnostic_pat_range_bdy`
386385
// converts `MAX+1` to `PosInfinity`, and we couldn't have `PosInfinity` in `self.lo`
@@ -941,11 +940,8 @@ impl ConstructorSet {
941940
}
942941
}
943942
&ty::Int(ity) => {
944-
let range = if ty.is_ptr_sized_integral()
945-
&& !cx.tcx.features().precise_pointer_size_matching
946-
{
947-
// The min/max values of `isize` are not allowed to be observed unless the
948-
// `precise_pointer_size_matching` feature is enabled.
943+
let range = if ty.is_ptr_sized_integral() {
944+
// The min/max values of `isize` are not allowed to be observed.
949945
IntRange { lo: NegInfinity, hi: PosInfinity }
950946
} else {
951947
let bits = Integer::from_int_ty(&cx.tcx, ity).size().bits() as u128;
@@ -956,11 +952,8 @@ impl ConstructorSet {
956952
Self::Integers { range_1: range, range_2: None }
957953
}
958954
&ty::Uint(uty) => {
959-
let range = if ty.is_ptr_sized_integral()
960-
&& !cx.tcx.features().precise_pointer_size_matching
961-
{
962-
// The max value of `usize` is not allowed to be observed unless the
963-
// `precise_pointer_size_matching` feature is enabled.
955+
let range = if ty.is_ptr_sized_integral() {
956+
// The max value of `usize` is not allowed to be observed.
964957
let lo = MaybeInfiniteInt::new_finite(cx.tcx, ty, 0);
965958
IntRange { lo, hi: PosInfinity }
966959
} else {

tests/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | match 0usize {
66
|
77
= note: the matched value is of type `usize`
88
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
9-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
109
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1110
|
1211
LL ~ 0..=usize::MAX => {},
@@ -21,7 +20,6 @@ LL | match 0isize {
2120
|
2221
= note: the matched value is of type `isize`
2322
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
24-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
2523
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
2624
|
2725
LL ~ isize::MIN..=isize::MAX => {},

tests/ui/pattern/usefulness/integer-ranges/pointer-sized-int.allow.stderr

-17
This file was deleted.

tests/ui/pattern/usefulness/integer-ranges/pointer-sized-int.deny.stderr

+12-23
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,150 @@
11
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
2-
--> $DIR/pointer-sized-int.rs:14:11
2+
--> $DIR/pointer-sized-int.rs:13:11
33
|
44
LL | match 0usize {
55
| ^^^^^^ pattern `usize::MAX..` not covered
66
|
77
= note: the matched value is of type `usize`
88
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
9-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
109
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1110
|
1211
LL ~ 0..=usize::MAX => {},
1312
LL + usize::MAX.. => todo!()
1413
|
1514

1615
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
17-
--> $DIR/pointer-sized-int.rs:19:11
16+
--> $DIR/pointer-sized-int.rs:18:11
1817
|
1918
LL | match 0isize {
2019
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
2120
|
2221
= note: the matched value is of type `isize`
2322
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
24-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
2523
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
2624
|
2725
LL ~ isize::MIN..=isize::MAX => {},
2826
LL + ..isize::MIN | isize::MAX.. => todo!()
2927
|
3028

3129
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
32-
--> $DIR/pointer-sized-int.rs:24:8
30+
--> $DIR/pointer-sized-int.rs:23:8
3331
|
3432
LL | m!(0usize, 0..=usize::MAX);
3533
| ^^^^^^ pattern `usize::MAX..` not covered
3634
|
3735
= note: the matched value is of type `usize`
3836
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
39-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
4037
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
4138
|
4239
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
4340
| +++++++++++++++++++++++++
4441

4542
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
46-
--> $DIR/pointer-sized-int.rs:26:8
43+
--> $DIR/pointer-sized-int.rs:25:8
4744
|
4845
LL | m!(0usize, 0..5 | 5..=usize::MAX);
4946
| ^^^^^^ pattern `usize::MAX..` not covered
5047
|
5148
= note: the matched value is of type `usize`
5249
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
53-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
5450
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
5551
|
5652
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
5753
| +++++++++++++++++++++++++
5854

5955
error[E0004]: non-exhaustive patterns: `usize::MAX..` not covered
60-
--> $DIR/pointer-sized-int.rs:28:8
56+
--> $DIR/pointer-sized-int.rs:27:8
6157
|
6258
LL | m!(0usize, 0..usize::MAX | usize::MAX);
6359
| ^^^^^^ pattern `usize::MAX..` not covered
6460
|
6561
= note: the matched value is of type `usize`
6662
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
67-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
6863
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
6964
|
7065
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
7166
| +++++++++++++++++++++++++
7267

7368
error[E0004]: non-exhaustive patterns: `(usize::MAX.., _)` not covered
74-
--> $DIR/pointer-sized-int.rs:30:8
69+
--> $DIR/pointer-sized-int.rs:29:8
7570
|
7671
LL | m!((0usize, true), (0..5, true) | (5..=usize::MAX, true) | (0..=usize::MAX, false));
7772
| ^^^^^^^^^^^^^^ pattern `(usize::MAX.., _)` not covered
7873
|
7974
= note: the matched value is of type `(usize, bool)`
8075
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
81-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
8276
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
8377
|
8478
LL | match $s { $($t)+ => {}, (usize::MAX.., _) => todo!() }
8579
| ++++++++++++++++++++++++++++++
8680

8781
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
88-
--> $DIR/pointer-sized-int.rs:39:8
82+
--> $DIR/pointer-sized-int.rs:38:8
8983
|
9084
LL | m!(0isize, isize::MIN..=isize::MAX);
9185
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
9286
|
9387
= note: the matched value is of type `isize`
9488
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
95-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
9689
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
9790
|
9891
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
9992
| ++++++++++++++++++++++++++++++++++++++++
10093

10194
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
102-
--> $DIR/pointer-sized-int.rs:41:8
95+
--> $DIR/pointer-sized-int.rs:40:8
10396
|
10497
LL | m!(0isize, isize::MIN..5 | 5..=isize::MAX);
10598
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
10699
|
107100
= note: the matched value is of type `isize`
108101
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
109-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
110102
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
111103
|
112104
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
113105
| ++++++++++++++++++++++++++++++++++++++++
114106

115107
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
116-
--> $DIR/pointer-sized-int.rs:43:8
108+
--> $DIR/pointer-sized-int.rs:42:8
117109
|
118110
LL | m!(0isize, isize::MIN..=-1 | 0 | 1..=isize::MAX);
119111
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
120112
|
121113
= note: the matched value is of type `isize`
122114
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
123-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
124115
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
125116
|
126117
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
127118
| ++++++++++++++++++++++++++++++++++++++++
128119

129120
error[E0004]: non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
130-
--> $DIR/pointer-sized-int.rs:45:8
121+
--> $DIR/pointer-sized-int.rs:44:8
131122
|
132123
LL | m!(0isize, isize::MIN..isize::MAX | isize::MAX);
133124
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
134125
|
135126
= note: the matched value is of type `isize`
136127
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
137-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
138128
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
139129
|
140130
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
141131
| ++++++++++++++++++++++++++++++++++++++++
142132

143133
error[E0004]: non-exhaustive patterns: `(..isize::MIN, _)` and `(isize::MAX.., _)` not covered
144-
--> $DIR/pointer-sized-int.rs:48:9
134+
--> $DIR/pointer-sized-int.rs:47:9
145135
|
146136
LL | (0isize, true),
147137
| ^^^^^^^^^^^^^^ patterns `(..isize::MIN, _)` and `(isize::MAX.., _)` not covered
148138
|
149139
= note: the matched value is of type `(isize, bool)`
150140
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
151-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
152141
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
153142
|
154143
LL | match $s { $($t)+ => {}, (..isize::MIN, _) | (isize::MAX.., _) => todo!() }
155144
| ++++++++++++++++++++++++++++++++++++++++++++++++++
156145

157146
error[E0004]: non-exhaustive patterns: type `usize` is non-empty
158-
--> $DIR/pointer-sized-int.rs:59:11
147+
--> $DIR/pointer-sized-int.rs:58:11
159148
|
160149
LL | match 7usize {}
161150
| ^^^^^^

tests/ui/pattern/usefulness/integer-ranges/pointer-sized-int.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// revisions: allow deny
1+
// revisions: deny
22
#![feature(exclusive_range_pattern)]
3-
#![cfg_attr(allow, feature(precise_pointer_size_matching))]
43
#![allow(overlapping_range_endpoints)]
54

65
macro_rules! m {
@@ -12,23 +11,23 @@ macro_rules! m {
1211
#[rustfmt::skip]
1312
fn main() {
1413
match 0usize {
15-
//[deny]~^ ERROR non-exhaustive patterns
14+
//~^ ERROR non-exhaustive patterns
1615
0..=usize::MAX => {}
1716
}
1817

1918
match 0isize {
20-
//[deny]~^ ERROR non-exhaustive patterns
19+
//~^ ERROR non-exhaustive patterns
2120
isize::MIN..=isize::MAX => {}
2221
}
2322

2423
m!(0usize, 0..=usize::MAX);
25-
//[deny]~^ ERROR non-exhaustive patterns
24+
//~^ ERROR non-exhaustive patterns
2625
m!(0usize, 0..5 | 5..=usize::MAX);
27-
//[deny]~^ ERROR non-exhaustive patterns
26+
//~^ ERROR non-exhaustive patterns
2827
m!(0usize, 0..usize::MAX | usize::MAX);
29-
//[deny]~^ ERROR non-exhaustive patterns
28+
//~^ ERROR non-exhaustive patterns
3029
m!((0usize, true), (0..5, true) | (5..=usize::MAX, true) | (0..=usize::MAX, false));
31-
//[deny]~^ ERROR non-exhaustive patterns
30+
//~^ ERROR non-exhaustive patterns
3231

3332
m!(0usize, 0..);
3433
m!(0usize, 0..5 | 5..);
@@ -37,18 +36,18 @@ fn main() {
3736
m!(0usize, 0..=usize::MAX | usize::MAX..);
3837

3938
m!(0isize, isize::MIN..=isize::MAX);
40-
//[deny]~^ ERROR non-exhaustive patterns
39+
//~^ ERROR non-exhaustive patterns
4140
m!(0isize, isize::MIN..5 | 5..=isize::MAX);
42-
//[deny]~^ ERROR non-exhaustive patterns
41+
//~^ ERROR non-exhaustive patterns
4342
m!(0isize, isize::MIN..=-1 | 0 | 1..=isize::MAX);
44-
//[deny]~^ ERROR non-exhaustive patterns
43+
//~^ ERROR non-exhaustive patterns
4544
m!(0isize, isize::MIN..isize::MAX | isize::MAX);
46-
//[deny]~^ ERROR non-exhaustive patterns
45+
//~^ ERROR non-exhaustive patterns
4746
m!(
4847
(0isize, true),
4948
(isize::MIN..5, true) | (5..=isize::MAX, true) | (isize::MIN..=isize::MAX, false)
5049
);
51-
//[deny]~^^^ ERROR non-exhaustive patterns
50+
//~^^^ ERROR non-exhaustive patterns
5251

5352
m!(0isize, ..0 | 0..);
5453
m!(0isize, ..5 | 5..);

tests/ui/pattern/usefulness/integer-ranges/precise_pointer_matching-message.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | match 0usize {
66
|
77
= note: the matched value is of type `usize`
88
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
9-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
109
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1110
|
1211
LL ~ 0..=usize::MAX => {},
@@ -21,7 +20,6 @@ LL | match 0isize {
2120
|
2221
= note: the matched value is of type `isize`
2322
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
24-
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `isize` matching
2523
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
2624
|
2725
LL ~ isize::MIN..=isize::MAX => {},

0 commit comments

Comments
 (0)