diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index c7deb30dd3f..4a94030e876 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -460,11 +460,15 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, .collect() } ty::TyChar if exhaustive_integer_patterns => { - let (min, max) = (0u128, char::MAX as u128); + let endpoint = |c: char| { + ty::Const::from_bits(cx.tcx, c as u128, cx.tcx.types.char) + }; value_constructors = true; - vec![ConstantRange(ty::Const::from_bits(cx.tcx, min, cx.tcx.types.char), - ty::Const::from_bits(cx.tcx, max, cx.tcx.types.char), - RangeEnd::Included)] + vec![ + // The valid Unicode Scalar Value ranges. + ConstantRange(endpoint('\u{0000}'), endpoint('\u{D7FF}'), RangeEnd::Included), + ConstantRange(endpoint('\u{E000}'), endpoint('\u{10FFFF}'), RangeEnd::Included), + ] } ty::TyInt(int_ty) if exhaustive_integer_patterns => { use syntax::ast::IntTy::*; diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index 39bac8919ff..80764415045 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -55,10 +55,19 @@ fn main() { } // Let's test other types too! - match '\u{0}' { + let c: char = '\u{0}'; + match c { '\u{0}' ..= char::MAX => {} // ok } + // We can actually get away with just covering the + // following two ranges, which correspond to all + // valid Unicode Scalar Values. + match c { + '\u{0000}' ..= '\u{D7FF}' => {} + '\u{E000}' ..= '\u{10_FFFF}' => {} + } + match 0usize { 0 ..= usize::MAX => {} // ok } @@ -84,7 +93,7 @@ fn main() { } match 0i8 { - -128..=127 => {} // ok + -128 ..= 127 => {} // ok } match 0i16 {