Skip to content

Commit e5c01f4

Browse files
committed
comment some ugly points in check_match
1 parent a6b3b01 commit e5c01f4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/librustc_const_eval/check_match.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,11 @@ pub fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> us
851851
ty::TyBox(_) => 1,
852852
ty::TySlice(_) => match *ctor {
853853
Slice(length) => length,
854-
ConstantValue(_) => 0,
855-
_ => bug!()
854+
ConstantValue(_) => {
855+
// TODO: this is utterly wrong, but required for byte arrays
856+
0
857+
}
858+
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
856859
},
857860
ty::TyRef(..) => 1,
858861
ty::TyAdt(adt, _) => {
@@ -981,20 +984,25 @@ pub fn specialize<'a, 'b, 'tcx>(
981984
Some(vec![wpat(&**inner)]),
982985

983986
PatKind::Lit(ref expr) => {
984-
if let Some(&ty::TyS { sty: ty::TyRef(_, mt), .. }) = r[col].1 {
985-
// HACK: handle string literals. A string literal pattern
986-
// serves both as an unary reference pattern and as a
987-
// nullary value pattern, depending on the type.
988-
Some(vec![(pat, Some(mt.ty))])
989-
} else {
990-
let expr_value = eval_const_expr(cx.tcx, &expr);
991-
match range_covered_by_constructor(
992-
cx.tcx, expr.span, constructor, &expr_value, &expr_value
993-
) {
994-
Ok(true) => Some(vec![]),
995-
Ok(false) => None,
996-
Err(ErrorReported) => None,
987+
match r[col].1 {
988+
Some(&ty::TyS { sty: ty::TyRef(_, mt), .. }) => {
989+
// HACK: handle string literals. A string literal pattern
990+
// serves both as an unary reference pattern and as a
991+
// nullary value pattern, depending on the type.
992+
Some(vec![(pat, Some(mt.ty))])
993+
}
994+
Some(ty) => {
995+
assert_eq!(constructor_arity(cx, constructor, ty), 0);
996+
let expr_value = eval_const_expr(cx.tcx, &expr);
997+
match range_covered_by_constructor(
998+
cx.tcx, expr.span, constructor, &expr_value, &expr_value
999+
) {
1000+
Ok(true) => Some(vec![]),
1001+
Ok(false) => None,
1002+
Err(ErrorReported) => None,
1003+
}
9971004
}
1005+
None => span_bug!(pat.span, "literal pattern {:?} has no type", pat)
9981006
}
9991007
}
10001008

0 commit comments

Comments
 (0)