1
Fork 0

Require just the Unicode Scalar Values to be matched for a char

This commit is contained in:
varkor 2018-05-21 20:40:38 +01:00
parent 9778a81e92
commit a20cb1084a
2 changed files with 19 additions and 6 deletions

View file

@ -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::*;

View file

@ -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 {