Skip to content

Commit f1f6d87

Browse files
committed
Stabilise exhaustive_integer_patterns
1 parent 3dde9e1 commit f1f6d87

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
622622
-> Vec<Constructor<'tcx>>
623623
{
624624
debug!("all_constructors({:?})", pcx.ty);
625-
let exhaustive_integer_patterns = cx.tcx.features().exhaustive_integer_patterns;
626625
let ctors = match pcx.ty.sty {
627626
ty::Bool => {
628627
[true, false].iter().map(|&b| {
@@ -652,7 +651,7 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
652651
.map(|v| Variant(v.did))
653652
.collect()
654653
}
655-
ty::Char if exhaustive_integer_patterns => {
654+
ty::Char => {
656655
vec![
657656
// The valid Unicode Scalar Value ranges.
658657
ConstantRange('\u{0000}' as u128,
@@ -667,14 +666,14 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
667666
),
668667
]
669668
}
670-
ty::Int(ity) if exhaustive_integer_patterns => {
669+
ty::Int(ity) => {
671670
// FIXME(49937): refactor these bit manipulations into interpret.
672671
let bits = Integer::from_attr(&cx.tcx, SignedInt(ity)).size().bits() as u128;
673672
let min = 1u128 << (bits - 1);
674673
let max = (1u128 << (bits - 1)) - 1;
675674
vec![ConstantRange(min, max, pcx.ty, RangeEnd::Included)]
676675
}
677-
ty::Uint(uty) if exhaustive_integer_patterns => {
676+
ty::Uint(uty) => {
678677
// FIXME(49937): refactor these bit manipulations into interpret.
679678
let bits = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size().bits() as u128;
680679
let max = !0u128 >> (128 - bits);
@@ -971,12 +970,10 @@ fn compute_missing_ctors<'a, 'tcx: 'a>(
971970
// If a constructor appears in a `match` arm, we can
972971
// eliminate it straight away.
973972
refined_ctors = vec![]
974-
} else if tcx.features().exhaustive_integer_patterns {
975-
if let Some(interval) = IntRange::from_ctor(tcx, used_ctor) {
976-
// Refine the required constructors for the type by subtracting
977-
// the range defined by the current constructor pattern.
978-
refined_ctors = interval.subtract_from(tcx, refined_ctors);
979-
}
973+
} else if let Some(interval) = IntRange::from_ctor(tcx, used_ctor) {
974+
// Refine the required constructors for the type by subtracting
975+
// the range defined by the current constructor pattern.
976+
refined_ctors = interval.subtract_from(tcx, refined_ctors);
980977
}
981978

982979
// If the constructor patterns that have been considered so far
@@ -1433,17 +1430,16 @@ fn slice_pat_covered_by_constructor<'tcx>(
14331430
// Whether to evaluate a constructor using exhaustive integer matching. This is true if the
14341431
// constructor is a range or constant with an integer type.
14351432
fn should_treat_range_exhaustively(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> bool {
1436-
if tcx.features().exhaustive_integer_patterns {
1437-
let ty = match ctor {
1438-
ConstantValue(value) => value.ty,
1439-
ConstantRange(_, _, ty, _) => ty,
1440-
_ => return false,
1441-
};
1442-
if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty {
1443-
return true;
1444-
}
1433+
let ty = match ctor {
1434+
ConstantValue(value) => value.ty,
1435+
ConstantRange(_, _, ty, _) => ty,
1436+
_ => return false,
1437+
};
1438+
if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty {
1439+
true
1440+
} else {
1441+
false
14451442
}
1446-
false
14471443
}
14481444

14491445
/// For exhaustive integer matching, some constructors are grouped within other constructors

src/libsyntax/feature_gate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,6 @@ declare_features! (
439439
// 'a: { break 'a; }
440440
(active, label_break_value, "1.28.0", Some(48594), None),
441441

442-
// Integer match exhaustiveness checking
443-
(active, exhaustive_integer_patterns, "1.30.0", Some(50907), None),
444442

445443
// #[doc(keyword = "...")]
446444
(active, doc_keyword, "1.28.0", Some(51315), None),
@@ -686,6 +684,8 @@ declare_features! (
686684
(accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None),
687685
// Allows use of the :literal macro fragment specifier (RFC 1576)
688686
(accepted, macro_literal_matcher, "1.31.0", Some(35625), None),
687+
// Integer match exhaustiveness checking (RFC 2591)
688+
(accepted, exhaustive_integer_patterns, "1.32.0", Some(50907), None),
689689
// Use `?` as the Kleene "at most one" operator
690690
(accepted, macro_at_most_once_rep, "1.32.0", Some(48075), None),
691691
);

src/test/ui/exhaustive_integer_patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(exhaustive_integer_patterns)]
1211
#![feature(exclusive_range_pattern)]
12+
1313
#![deny(unreachable_patterns)]
1414

1515
use std::{char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128};

0 commit comments

Comments
 (0)