Skip to content

Commit 07064de

Browse files
committed
No longer return value_constructors for all_constructors
1 parent d27c21c commit 07064de

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,10 @@ impl<'tcx> Witness<'tcx> {
426426
/// Option<!> we do not include Some(_) in the returned list of constructors.
427427
fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
428428
pcx: PatternContext<'tcx>)
429-
-> (Vec<Constructor<'tcx>>, bool)
429+
-> Vec<Constructor<'tcx>>
430430
{
431431
debug!("all_constructors({:?})", pcx.ty);
432432
let exhaustive_integer_patterns = cx.tcx.features().exhaustive_integer_patterns;
433-
let mut value_constructors = false;
434433
let ctors = match pcx.ty.sty {
435434
ty::TyBool => {
436435
[true, false].iter().map(|&b| {
@@ -461,7 +460,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
461460
.collect()
462461
}
463462
ty::TyChar if exhaustive_integer_patterns => {
464-
value_constructors = true;
465463
let endpoint = |c: char| {
466464
let ty = ty::ParamEnv::empty().and(cx.tcx.types.char);
467465
ty::Const::from_bits(cx.tcx, c as u128, ty)
@@ -473,7 +471,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
473471
]
474472
}
475473
ty::TyInt(ity) if exhaustive_integer_patterns => {
476-
value_constructors = true;
477474
// FIXME(49937): refactor these bit manipulations into interpret.
478475
let bits = Integer::from_attr(cx.tcx, SignedInt(ity)).size().bits() as u128;
479476
let min = 1u128 << (bits - 1);
@@ -484,7 +481,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
484481
RangeEnd::Included)]
485482
}
486483
ty::TyUint(uty) if exhaustive_integer_patterns => {
487-
value_constructors = true;
488484
// FIXME(49937): refactor these bit manipulations into interpret.
489485
let bits = Integer::from_attr(cx.tcx, UnsignedInt(uty)).size().bits() as u128;
490486
let max = !0u128 >> (128 - bits);
@@ -501,7 +497,7 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
501497
}
502498
}
503499
};
504-
(ctors, value_constructors)
500+
ctors
505501
}
506502

507503
fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
@@ -810,22 +806,23 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
810806
debug!("used_ctors = {:#?}", used_ctors);
811807
// `all_ctors` are all the constructors for the given type, which
812808
// should all be represented (or caught with the wild pattern `_`).
813-
// `value_constructors` is true if we may exhaustively consider all
814-
// the possible values (e.g. integers) of a type as its constructors.
815-
let (all_ctors, value_constructors) = all_constructors(cx, pcx);
809+
let all_ctors = all_constructors(cx, pcx);
816810
debug!("all_ctors = {:#?}", all_ctors);
817811

812+
// The only constructor patterns for which it is valid to
813+
// treat the values as constructors are ranges (see
814+
// `all_constructors` for details).
815+
let exhaustive_integer_patterns = cx.tcx.features().exhaustive_integer_patterns;
816+
let consider_value_constructors = exhaustive_integer_patterns
817+
&& all_ctors.iter().all(|ctor| match ctor {
818+
ConstantRange(..) => true,
819+
_ => false,
820+
});
821+
818822
// `missing_ctors` are those that should have appeared
819823
// as patterns in the `match` expression, but did not.
820824
let mut missing_ctors = vec![];
821825
for req_ctor in &all_ctors {
822-
// The only constructor patterns for which it is valid to
823-
// treat the values as constructors are ranges (see
824-
// `all_constructors` for details).
825-
let consider_value_constructors = value_constructors && match req_ctor {
826-
ConstantRange(..) => true,
827-
_ => false,
828-
};
829826
if consider_value_constructors {
830827
let mut refined_ctors = vec![req_ctor.clone()];
831828
for used_ctor in &used_ctors {
@@ -886,7 +883,7 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
886883
let is_non_exhaustive = is_privately_empty || is_declared_nonexhaustive;
887884

888885
if missing_ctors.is_empty() && !is_non_exhaustive {
889-
if value_constructors {
886+
if consider_value_constructors {
890887
// If we've successfully matched every value
891888
// of the type, then we're done.
892889
NotUseful
@@ -962,7 +959,7 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
962959
witness
963960
}).collect()
964961
} else {
965-
if value_constructors {
962+
if consider_value_constructors {
966963
// If we've been trying to exhaustively match
967964
// over the domain of values for a type,
968965
// then we can provide better diagnostics

0 commit comments

Comments
 (0)