From 0d0da359a3f6897b3f8ecd935794f8f4807547c3 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 15 Oct 2023 15:31:53 +0200 Subject: [PATCH] Review --- compiler/rustc_middle/src/thir.rs | 3 +++ .../src/thir/pattern/deconstruct_pat.rs | 22 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 9d876f839aa9..2960cf67963f 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -979,6 +979,9 @@ impl<'tcx> PatRangeBoundary<'tcx> { ) -> Option { use PatRangeBoundary::*; match (self, other) { + // When comparing with infinities, we must remember that `0u8..` and `0u8..=255` + // describe the same range. These two shortcuts are ok, but for the rest we must check + // bit values. (PosInfinity, PosInfinity) => return Some(Ordering::Equal), (NegInfinity, NegInfinity) => return Some(Ordering::Equal), diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs index cb903c1b6a65..330ed5d8f3d7 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs @@ -1192,17 +1192,25 @@ impl ConstructorSet { } } ConstructorSet::Bool => { - let mut seen_bools = [false, false]; + let mut seen_false = false; + let mut seen_true = false; for b in seen.map(|ctor| ctor.as_bool().unwrap()) { - seen_bools[b as usize] = true; - } - for b in [true, false] { - if seen_bools[b as usize] { - present.push(Bool(b)); + if b { + seen_true = true; } else { - missing.push(Bool(b)); + seen_false = true; } } + if seen_false { + present.push(Bool(false)); + } else { + missing.push(Bool(false)); + } + if seen_true { + present.push(Bool(true)); + } else { + missing.push(Bool(true)); + } } ConstructorSet::Integers { range_1, range_2 } => { let seen_ranges: Vec<_> =