@@ -32,7 +32,7 @@ use syntax::ptr::P;
32
32
use syntax:: visit:: { mod, Visitor , FnKind } ;
33
33
use util:: ppaux:: ty_to_string;
34
34
35
- static DUMMY_WILD_PAT : Pat = Pat {
35
+ pub const DUMMY_WILD_PAT : Pat = Pat {
36
36
id : DUMMY_NODE_ID ,
37
37
node : PatWild ( PatWildSingle ) ,
38
38
span : DUMMY_SP
@@ -299,9 +299,10 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
299
299
fn check_exhaustive ( cx : & MatchCheckCtxt , sp : Span , matrix : & Matrix ) {
300
300
match is_useful ( cx, matrix, & [ & DUMMY_WILD_PAT ] , ConstructWitness ) {
301
301
UsefulWithWitness ( pats) => {
302
+ let dummy = DUMMY_WILD_PAT . clone ( ) ;
302
303
let witness = match pats. as_slice ( ) {
303
304
[ ref witness] => & * * witness,
304
- [ ] => & DUMMY_WILD_PAT ,
305
+ [ ] => & dummy ,
305
306
_ => unreachable ! ( )
306
307
} ;
307
308
span_err ! ( cx. tcx. sess, sp, E0004 ,
@@ -349,7 +350,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
349
350
PatIdent ( ..) | PatEnum ( ..) => {
350
351
let def = self . tcx . def_map . borrow ( ) . find_copy ( & pat. id ) ;
351
352
match def {
352
- Some ( DefStatic ( did, _ ) ) => match lookup_const_by_id ( self . tcx , did) {
353
+ Some ( DefConst ( did) ) => match lookup_const_by_id ( self . tcx , did) {
353
354
Some ( const_expr) => {
354
355
const_expr_to_pat ( self . tcx , const_expr) . map ( |mut new_pat| {
355
356
new_pat. span = pat. span ;
@@ -359,7 +360,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
359
360
None => {
360
361
self . failed = true ;
361
362
span_err ! ( self . tcx. sess, pat. span, E0158 ,
362
- "extern statics cannot be referenced in patterns" ) ;
363
+ "statics cannot be referenced in patterns" ) ;
363
364
pat
364
365
}
365
366
} ,
@@ -555,8 +556,9 @@ fn is_useful(cx: &MatchCheckCtxt,
555
556
let arity = constructor_arity ( cx, & c, left_ty) ;
556
557
let mut result = {
557
558
let pat_slice = pats. as_slice ( ) ;
559
+ let dummy = DUMMY_WILD_PAT . clone ( ) ;
558
560
let subpats = Vec :: from_fn ( arity, |i| {
559
- pat_slice. get ( i) . map_or ( & DUMMY_WILD_PAT , |p| & * * p)
561
+ pat_slice. get ( i) . map_or ( & dummy , |p| & * * p)
560
562
} ) ;
561
563
vec ! [ construct_witness( cx, & c, subpats, left_ty) ]
562
564
} ;
@@ -578,8 +580,9 @@ fn is_useful(cx: &MatchCheckCtxt,
578
580
} ) . collect ( ) ;
579
581
match is_useful ( cx, & matrix, v. tail ( ) , witness) {
580
582
UsefulWithWitness ( pats) => {
583
+ let dummy = DUMMY_WILD_PAT . clone ( ) ;
581
584
let arity = constructor_arity ( cx, & constructor, left_ty) ;
582
- let wild_pats = Vec :: from_elem ( arity, & DUMMY_WILD_PAT ) ;
585
+ let wild_pats = Vec :: from_elem ( arity, & dummy ) ;
583
586
let enum_pat = construct_witness ( cx, & constructor, wild_pats, left_ty) ;
584
587
let mut new_pats = vec ! [ enum_pat] ;
585
588
new_pats. extend ( pats. into_iter ( ) ) ;
@@ -600,10 +603,11 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix,
600
603
v : & [ & Pat ] , ctor : Constructor , lty : ty:: t ,
601
604
witness : WitnessPreference ) -> Usefulness {
602
605
let arity = constructor_arity ( cx, & ctor, lty) ;
606
+ let dummy = DUMMY_WILD_PAT . clone ( ) ;
603
607
let matrix = Matrix ( m. iter ( ) . filter_map ( |r| {
604
- specialize ( cx, r. as_slice ( ) , & ctor, 0 u, arity)
608
+ specialize ( cx, r. as_slice ( ) , & dummy , & ctor, 0 u, arity)
605
609
} ) . collect ( ) ) ;
606
- match specialize ( cx, v, & ctor, 0 u, arity) {
610
+ match specialize ( cx, v, & dummy , & ctor, 0 u, arity) {
607
611
Some ( v) => is_useful ( cx, & matrix, v. as_slice ( ) , witness) ,
608
612
None => NotUseful
609
613
}
@@ -624,23 +628,26 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
624
628
match pat. node {
625
629
PatIdent ( ..) =>
626
630
match cx. tcx . def_map . borrow ( ) . find ( & pat. id ) {
627
- Some ( & DefStatic ( ..) ) =>
628
- cx. tcx . sess . span_bug ( pat. span , "static pattern should've been rewritten" ) ,
631
+ Some ( & DefConst ( ..) ) =>
632
+ cx. tcx . sess . span_bug ( pat. span , "const pattern should've \
633
+ been rewritten") ,
629
634
Some ( & DefStruct ( _) ) => vec ! ( Single ) ,
630
635
Some ( & DefVariant ( _, id, _) ) => vec ! ( Variant ( id) ) ,
631
636
_ => vec ! ( )
632
637
} ,
633
638
PatEnum ( ..) =>
634
639
match cx. tcx . def_map . borrow ( ) . find ( & pat. id ) {
635
- Some ( & DefStatic ( ..) ) =>
636
- cx. tcx . sess . span_bug ( pat. span , "static pattern should've been rewritten" ) ,
640
+ Some ( & DefConst ( ..) ) =>
641
+ cx. tcx . sess . span_bug ( pat. span , "static pattern should've \
642
+ been rewritten") ,
637
643
Some ( & DefVariant ( _, id, _) ) => vec ! ( Variant ( id) ) ,
638
644
_ => vec ! ( Single )
639
645
} ,
640
646
PatStruct ( ..) =>
641
647
match cx. tcx . def_map . borrow ( ) . find ( & pat. id ) {
642
- Some ( & DefStatic ( ..) ) =>
643
- cx. tcx . sess . span_bug ( pat. span , "static pattern should've been rewritten" ) ,
648
+ Some ( & DefConst ( ..) ) =>
649
+ cx. tcx . sess . span_bug ( pat. span , "static pattern should've \
650
+ been rewritten") ,
644
651
Some ( & DefVariant ( _, id, _) ) => vec ! ( Variant ( id) ) ,
645
652
_ => vec ! ( Single )
646
653
} ,
@@ -722,40 +729,42 @@ fn range_covered_by_constructor(ctor: &Constructor,
722
729
/// different patterns.
723
730
/// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing
724
731
/// fields filled with wild patterns.
725
- pub fn specialize < ' a > ( cx : & MatchCheckCtxt , r : & [ & ' a Pat ] ,
732
+ pub fn specialize < ' a > ( cx : & MatchCheckCtxt , r : & [ & ' a Pat ] , dummy : & ' a Pat ,
726
733
constructor : & Constructor , col : uint , arity : uint ) -> Option < Vec < & ' a Pat > > {
727
734
let & Pat {
728
735
id : pat_id, node : ref node, span : pat_span
729
736
} = raw_pat ( r[ col] ) ;
730
737
let head: Option < Vec < & Pat > > = match node {
731
738
732
739
& PatWild ( _) =>
733
- Some ( Vec :: from_elem ( arity, & DUMMY_WILD_PAT ) ) ,
740
+ Some ( Vec :: from_elem ( arity, dummy ) ) ,
734
741
735
742
& PatIdent ( _, _, _) => {
736
743
let opt_def = cx. tcx . def_map . borrow ( ) . find_copy ( & pat_id) ;
737
744
match opt_def {
738
- Some ( DefStatic ( ..) ) =>
739
- cx. tcx . sess . span_bug ( pat_span, "static pattern should've been rewritten" ) ,
745
+ Some ( DefConst ( ..) ) =>
746
+ cx. tcx . sess . span_bug ( pat_span, "const pattern should've \
747
+ been rewritten") ,
740
748
Some ( DefVariant ( _, id, _) ) => if * constructor == Variant ( id) {
741
749
Some ( vec ! ( ) )
742
750
} else {
743
751
None
744
752
} ,
745
- _ => Some ( Vec :: from_elem ( arity, & DUMMY_WILD_PAT ) )
753
+ _ => Some ( Vec :: from_elem ( arity, dummy ) )
746
754
}
747
755
}
748
756
749
757
& PatEnum ( _, ref args) => {
750
758
let def = cx. tcx . def_map . borrow ( ) . get_copy ( & pat_id) ;
751
759
match def {
752
- DefStatic ( ..) =>
753
- cx. tcx . sess . span_bug ( pat_span, "static pattern should've been rewritten" ) ,
760
+ DefConst ( ..) =>
761
+ cx. tcx . sess . span_bug ( pat_span, "const pattern should've \
762
+ been rewritten") ,
754
763
DefVariant ( _, id, _) if * constructor != Variant ( id) => None ,
755
764
DefVariant ( ..) | DefStruct ( ..) => {
756
765
Some ( match args {
757
766
& Some ( ref args) => args. iter ( ) . map ( |p| & * * p) . collect ( ) ,
758
- & None => Vec :: from_elem ( arity, & DUMMY_WILD_PAT )
767
+ & None => Vec :: from_elem ( arity, dummy )
759
768
} )
760
769
}
761
770
_ => None
@@ -766,8 +775,9 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
766
775
// Is this a struct or an enum variant?
767
776
let def = cx. tcx . def_map . borrow ( ) . get_copy ( & pat_id) ;
768
777
let class_id = match def {
769
- DefStatic ( ..) =>
770
- cx. tcx . sess . span_bug ( pat_span, "static pattern should've been rewritten" ) ,
778
+ DefConst ( ..) =>
779
+ cx. tcx . sess . span_bug ( pat_span, "const pattern should've \
780
+ been rewritten") ,
771
781
DefVariant ( _, variant_id, _) => if * constructor == Variant ( variant_id) {
772
782
Some ( variant_id)
773
783
} else {
@@ -790,7 +800,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
790
800
let args = struct_fields. iter ( ) . map ( |sf| {
791
801
match pattern_fields. iter ( ) . find ( |f| f. ident . name == sf. name ) {
792
802
Some ( ref f) => & * f. pat ,
793
- _ => & DUMMY_WILD_PAT
803
+ _ => dummy
794
804
}
795
805
} ) . collect ( ) ;
796
806
args
@@ -833,13 +843,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
833
843
// Fixed-length vectors.
834
844
Single => {
835
845
let mut pats: Vec < & Pat > = before. iter ( ) . map ( |p| & * * p) . collect ( ) ;
836
- pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| & DUMMY_WILD_PAT ) ;
846
+ pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| dummy ) ;
837
847
pats. extend ( after. iter ( ) . map ( |p| & * * p) ) ;
838
848
Some ( pats)
839
849
} ,
840
850
Slice ( length) if before. len ( ) + after. len ( ) <= length && slice. is_some ( ) => {
841
851
let mut pats: Vec < & Pat > = before. iter ( ) . map ( |p| & * * p) . collect ( ) ;
842
- pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| & DUMMY_WILD_PAT ) ;
852
+ pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| dummy ) ;
843
853
pats. extend ( after. iter ( ) . map ( |p| & * * p) ) ;
844
854
Some ( pats)
845
855
} ,
0 commit comments