@@ -851,8 +851,11 @@ pub fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> us
851
851
ty:: TyBox ( _) => 1 ,
852
852
ty:: TySlice ( _) => match * ctor {
853
853
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)
856
859
} ,
857
860
ty:: TyRef ( ..) => 1 ,
858
861
ty:: TyAdt ( adt, _) => {
@@ -981,20 +984,25 @@ pub fn specialize<'a, 'b, 'tcx>(
981
984
Some ( vec ! [ wpat( & * * inner) ] ) ,
982
985
983
986
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
+ }
997
1004
}
1005
+ None => span_bug ! ( pat. span, "literal pattern {:?} has no type" , pat)
998
1006
}
999
1007
}
1000
1008
0 commit comments