@@ -191,7 +191,7 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: Vec<@Pat> ) {
191
191
}
192
192
}
193
193
}
194
- ty:: ty_vec( ..) => {
194
+ ty:: ty_vec( ..) | ty :: ty_rptr ( .. ) => {
195
195
match * ctor {
196
196
vec( n) => Some ( format ! ( "vectors of length {}" , n) ) ,
197
197
_ => None
@@ -258,50 +258,57 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
258
258
None => {
259
259
match ty:: get ( left_ty) . sty {
260
260
ty:: ty_bool => {
261
- match is_useful_specialized ( cx, m, v,
262
- val ( const_bool ( true ) ) ,
263
- 0 u, left_ty) {
264
- not_useful => {
265
- is_useful_specialized ( cx, m, v,
266
- val ( const_bool ( false ) ) ,
267
- 0 u, left_ty)
261
+ match is_useful_specialized ( cx, m, v,
262
+ val ( const_bool ( true ) ) ,
263
+ 0 u, left_ty) {
264
+ not_useful => {
265
+ is_useful_specialized ( cx, m, v,
266
+ val ( const_bool ( false ) ) ,
267
+ 0 u, left_ty)
268
+ }
269
+ ref u => ( * u) . clone ( ) ,
268
270
}
269
- ref u => ( * u) . clone ( ) ,
270
- }
271
271
}
272
272
ty:: ty_enum( eid, _) => {
273
- for va in ( * ty:: enum_variants ( cx. tcx , eid) ) . iter ( ) {
274
- match is_useful_specialized ( cx, m, v, variant ( va. id ) ,
275
- va. args . len ( ) , left_ty) {
276
- not_useful => ( ) ,
277
- ref u => return ( * u) . clone ( ) ,
278
- }
279
- }
280
- not_useful
273
+ for va in ( * ty:: enum_variants ( cx. tcx , eid) ) . iter ( ) {
274
+ match is_useful_specialized ( cx, m, v, variant ( va. id ) ,
275
+ va. args . len ( ) , left_ty) {
276
+ not_useful => ( ) ,
277
+ ref u => return ( * u) . clone ( ) ,
278
+ }
279
+ }
280
+ not_useful
281
281
}
282
- ty:: ty_vec( _, ty :: VstoreFixed ( n) ) => {
283
- is_useful_specialized ( cx, m, v, vec ( n) , n, left_ty)
282
+ ty:: ty_vec( _, Some ( n) ) => {
283
+ is_useful_specialized ( cx, m, v, vec ( n) , n, left_ty)
284
284
}
285
- ty:: ty_vec( ..) => {
286
- let max_len = m. iter ( ) . rev ( ) . fold ( 0 , |max_len, r| {
287
- match r. get ( 0 ) . node {
288
- PatVec ( ref before, _, ref after) => {
289
- cmp:: max ( before. len ( ) + after. len ( ) , max_len)
290
- }
291
- _ => max_len
285
+ ty:: ty_vec( ..) => fail ! ( "impossible case" ) ,
286
+ ty:: ty_rptr( _, ty:: mt { ty : ty, ..} ) | ty:: ty_uniq( ty) => match ty:: get ( ty) . sty {
287
+ ty:: ty_vec( _, None ) => {
288
+ let max_len = m. iter ( ) . rev ( ) . fold ( 0 , |max_len, r| {
289
+ match r. get ( 0 ) . node {
290
+ PatVec ( ref before, _, ref after) => {
291
+ cmp:: max ( before. len ( ) + after. len ( ) , max_len)
292
+ }
293
+ _ => max_len
294
+ }
295
+ } ) ;
296
+ for n in iter:: range ( 0 u, max_len + 1 ) {
297
+ match is_useful_specialized ( cx, m, v, vec ( n) , n, left_ty) {
298
+ not_useful => ( ) ,
299
+ ref u => return ( * u) . clone ( ) ,
300
+ }
301
+ }
302
+ not_useful
292
303
}
293
- } ) ;
294
- for n in iter:: range ( 0 u, max_len + 1 ) {
295
- match is_useful_specialized ( cx, m, v, vec ( n) , n, left_ty) {
296
- not_useful => ( ) ,
297
- ref u => return ( * u) . clone ( ) ,
304
+ _ => {
305
+ let arity = ctor_arity ( cx, & single, left_ty) ;
306
+ is_useful_specialized ( cx, m, v, single, arity, left_ty)
298
307
}
299
- }
300
- not_useful
301
- }
308
+ } ,
302
309
_ => {
303
- let arity = ctor_arity ( cx, & single, left_ty) ;
304
- is_useful_specialized ( cx, m, v, single, arity, left_ty)
310
+ let arity = ctor_arity ( cx, & single, left_ty) ;
311
+ is_useful_specialized ( cx, m, v, single, arity, left_ty)
305
312
}
306
313
}
307
314
}
@@ -394,17 +401,16 @@ fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
394
401
}
395
402
396
403
fn missing_ctor ( cx : & MatchCheckCtxt ,
397
- m : & matrix ,
398
- left_ty : ty:: t )
399
- -> Option < ctor > {
400
- match ty:: get ( left_ty) . sty {
401
- ty:: ty_box( _) | ty:: ty_uniq( _) | ty:: ty_rptr( ..) | ty:: ty_tup( _) |
402
- ty:: ty_struct( ..) => {
403
- for r in m. iter ( ) {
404
- if !is_wild ( cx, * r. get ( 0 ) ) { return None ; }
405
- }
406
- return Some ( single) ;
407
- }
404
+ m : & matrix ,
405
+ left_ty : ty:: t )
406
+ -> Option < ctor > {
407
+ return match ty:: get ( left_ty) . sty {
408
+ ty:: ty_box( _) | ty:: ty_tup( _) |
409
+ ty:: ty_struct( ..) => check_matrix_for_wild ( cx, m) ,
410
+ ty:: ty_uniq( ty) | ty:: ty_rptr( _, ty:: mt { ty : ty, ..} ) => match ty:: get ( ty) . sty {
411
+ ty:: ty_vec( _, None ) => ctor_for_slice ( m) ,
412
+ _ => check_matrix_for_wild ( cx, m) ,
413
+ } ,
408
414
ty:: ty_enum( eid, _) => {
409
415
let mut found = Vec :: new ( ) ;
410
416
for r in m. iter ( ) {
@@ -441,7 +447,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
441
447
else if true_found { Some ( val ( const_bool ( false ) ) ) }
442
448
else { Some ( val ( const_bool ( true ) ) ) }
443
449
}
444
- ty:: ty_vec( _, ty :: VstoreFixed ( n) ) => {
450
+ ty:: ty_vec( _, Some ( n) ) => {
445
451
let mut missing = true ;
446
452
let mut wrong = false ;
447
453
for r in m. iter ( ) {
@@ -464,8 +470,19 @@ fn missing_ctor(cx: &MatchCheckCtxt,
464
470
_ => None
465
471
}
466
472
}
467
- ty:: ty_vec( ..) => {
473
+ ty:: ty_vec( ..) => fail ! ( "impossible case" ) ,
474
+ _ => Some ( single)
475
+ } ;
476
+
477
+ fn check_matrix_for_wild ( cx : & MatchCheckCtxt , m : & matrix ) -> Option < ctor > {
478
+ for r in m. iter ( ) {
479
+ if !is_wild ( cx, * r. get ( 0 ) ) { return None ; }
480
+ }
481
+ return Some ( single) ;
482
+ }
468
483
484
+ // For slice and ~[T].
485
+ fn ctor_for_slice ( m : & matrix ) -> Option < ctor > {
469
486
// Find the lengths and slices of all vector patterns.
470
487
let mut vec_pat_lens = m. iter ( ) . filter_map ( |r| {
471
488
match r. get ( 0 ) . node {
@@ -511,31 +528,37 @@ fn missing_ctor(cx: &MatchCheckCtxt,
511
528
Some ( k) => Some ( vec ( k) ) ,
512
529
None => None
513
530
}
514
- }
515
- _ => Some ( single)
516
531
}
517
532
}
518
533
519
534
fn ctor_arity ( cx : & MatchCheckCtxt , ctor : & ctor , ty : ty:: t ) -> uint {
520
- match ty:: get ( ty) . sty {
521
- ty:: ty_tup( ref fs) => fs. len ( ) ,
522
- ty:: ty_box( _) | ty:: ty_uniq( _) | ty:: ty_rptr( ..) => 1 u,
523
- ty:: ty_enum( eid, _) => {
524
- let id = match * ctor { variant( id) => id,
525
- _ => fail ! ( "impossible case" ) } ;
526
- match ty:: enum_variants ( cx. tcx , eid) . iter ( ) . find ( |v| v. id == id ) {
527
- Some ( v) => v. args . len ( ) ,
528
- None => fail ! ( "impossible case" )
529
- }
530
- }
531
- ty:: ty_struct( cid, _) => ty:: lookup_struct_fields ( cx. tcx , cid) . len ( ) ,
532
- ty:: ty_vec( ..) => {
535
+ fn vec_ctor_arity ( ctor : & ctor ) -> uint {
533
536
match * ctor {
534
- vec( n) => n,
535
- _ => 0 u
537
+ vec( n) => n,
538
+ _ => 0 u
536
539
}
537
- }
538
- _ => 0 u
540
+ }
541
+
542
+ match ty:: get ( ty) . sty {
543
+ ty:: ty_tup( ref fs) => fs. len ( ) ,
544
+ ty:: ty_box( _) => 1 u,
545
+ ty:: ty_uniq( ty) | ty:: ty_rptr( _, ty:: mt { ty : ty, ..} ) => match ty:: get ( ty) . sty {
546
+ ty:: ty_vec( _, None ) => vec_ctor_arity ( ctor) ,
547
+ _ => 1 u,
548
+ } ,
549
+ ty:: ty_enum( eid, _) => {
550
+ let id = match * ctor {
551
+ variant( id) => id,
552
+ _ => fail ! ( "impossible case" )
553
+ } ;
554
+ match ty:: enum_variants ( cx. tcx , eid) . iter ( ) . find ( |v| v. id == id ) {
555
+ Some ( v) => v. args . len ( ) ,
556
+ None => fail ! ( "impossible case" )
557
+ }
558
+ }
559
+ ty:: ty_struct( cid, _) => ty:: lookup_struct_fields ( cx. tcx , cid) . len ( ) ,
560
+ ty:: ty_vec( _, Some ( _) ) => vec_ctor_arity ( ctor) ,
561
+ _ => 0 u
539
562
}
540
563
}
541
564
0 commit comments