@@ -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
- pub const DUMMY_WILD_PAT : Pat = Pat {
35
+ pub const DUMMY_WILD_PAT : & ' static Pat = & Pat {
36
36
id : DUMMY_NODE_ID ,
37
37
node : PatWild ( PatWildSingle ) ,
38
38
span : DUMMY_SP
@@ -297,12 +297,11 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
297
297
}
298
298
299
299
fn check_exhaustive ( cx : & MatchCheckCtxt , sp : Span , matrix : & Matrix ) {
300
- match is_useful ( cx, matrix, & [ & DUMMY_WILD_PAT ] , ConstructWitness ) {
300
+ match is_useful ( cx, matrix, & [ DUMMY_WILD_PAT ] , ConstructWitness ) {
301
301
UsefulWithWitness ( pats) => {
302
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
303
302
let witness = match pats. as_slice ( ) {
304
303
[ ref witness] => & * * witness,
305
- [ ] => & dummy ,
304
+ [ ] => DUMMY_WILD_PAT ,
306
305
_ => unreachable ! ( )
307
306
} ;
308
307
span_err ! ( cx. tcx. sess, sp, E0004 ,
@@ -556,9 +555,8 @@ fn is_useful(cx: &MatchCheckCtxt,
556
555
let arity = constructor_arity ( cx, & c, left_ty) ;
557
556
let mut result = {
558
557
let pat_slice = pats. as_slice ( ) ;
559
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
560
558
let subpats = Vec :: from_fn ( arity, |i| {
561
- pat_slice. get ( i) . map_or ( & dummy , |p| & * * p)
559
+ pat_slice. get ( i) . map_or ( DUMMY_WILD_PAT , |p| & * * p)
562
560
} ) ;
563
561
vec ! [ construct_witness( cx, & c, subpats, left_ty) ]
564
562
} ;
@@ -580,9 +578,8 @@ fn is_useful(cx: &MatchCheckCtxt,
580
578
} ) . collect ( ) ;
581
579
match is_useful ( cx, & matrix, v. tail ( ) , witness) {
582
580
UsefulWithWitness ( pats) => {
583
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
584
581
let arity = constructor_arity ( cx, & constructor, left_ty) ;
585
- let wild_pats = Vec :: from_elem ( arity, & dummy ) ;
582
+ let wild_pats = Vec :: from_elem ( arity, DUMMY_WILD_PAT ) ;
586
583
let enum_pat = construct_witness ( cx, & constructor, wild_pats, left_ty) ;
587
584
let mut new_pats = vec ! [ enum_pat] ;
588
585
new_pats. extend ( pats. into_iter ( ) ) ;
@@ -603,11 +600,10 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix,
603
600
v : & [ & Pat ] , ctor : Constructor , lty : ty:: t ,
604
601
witness : WitnessPreference ) -> Usefulness {
605
602
let arity = constructor_arity ( cx, & ctor, lty) ;
606
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
607
603
let matrix = Matrix ( m. iter ( ) . filter_map ( |r| {
608
- specialize ( cx, r. as_slice ( ) , & dummy , & ctor, 0 u, arity)
604
+ specialize ( cx, r. as_slice ( ) , & ctor, 0 u, arity)
609
605
} ) . collect ( ) ) ;
610
- match specialize ( cx, v, & dummy , & ctor, 0 u, arity) {
606
+ match specialize ( cx, v, & ctor, 0 u, arity) {
611
607
Some ( v) => is_useful ( cx, & matrix, v. as_slice ( ) , witness) ,
612
608
None => NotUseful
613
609
}
@@ -729,15 +725,15 @@ fn range_covered_by_constructor(ctor: &Constructor,
729
725
/// different patterns.
730
726
/// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing
731
727
/// fields filled with wild patterns.
732
- pub fn specialize < ' a > ( cx : & MatchCheckCtxt , r : & [ & ' a Pat ] , dummy : & ' a Pat ,
728
+ pub fn specialize < ' a > ( cx : & MatchCheckCtxt , r : & [ & ' a Pat ] ,
733
729
constructor : & Constructor , col : uint , arity : uint ) -> Option < Vec < & ' a Pat > > {
734
730
let & Pat {
735
731
id : pat_id, node : ref node, span : pat_span
736
732
} = raw_pat ( r[ col] ) ;
737
733
let head: Option < Vec < & Pat > > = match node {
738
734
739
735
& PatWild ( _) =>
740
- Some ( Vec :: from_elem ( arity, dummy ) ) ,
736
+ Some ( Vec :: from_elem ( arity, DUMMY_WILD_PAT ) ) ,
741
737
742
738
& PatIdent ( _, _, _) => {
743
739
let opt_def = cx. tcx . def_map . borrow ( ) . find_copy ( & pat_id) ;
@@ -750,7 +746,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
750
746
} else {
751
747
None
752
748
} ,
753
- _ => Some ( Vec :: from_elem ( arity, dummy ) )
749
+ _ => Some ( Vec :: from_elem ( arity, DUMMY_WILD_PAT ) )
754
750
}
755
751
}
756
752
@@ -764,7 +760,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
764
760
DefVariant ( ..) | DefStruct ( ..) => {
765
761
Some ( match args {
766
762
& Some ( ref args) => args. iter ( ) . map ( |p| & * * p) . collect ( ) ,
767
- & None => Vec :: from_elem ( arity, dummy )
763
+ & None => Vec :: from_elem ( arity, DUMMY_WILD_PAT )
768
764
} )
769
765
}
770
766
_ => None
@@ -800,7 +796,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
800
796
let args = struct_fields. iter ( ) . map ( |sf| {
801
797
match pattern_fields. iter ( ) . find ( |f| f. ident . name == sf. name ) {
802
798
Some ( ref f) => & * f. pat ,
803
- _ => dummy
799
+ _ => DUMMY_WILD_PAT
804
800
}
805
801
} ) . collect ( ) ;
806
802
args
@@ -843,13 +839,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
843
839
// Fixed-length vectors.
844
840
Single => {
845
841
let mut pats: Vec < & Pat > = before. iter ( ) . map ( |p| & * * p) . collect ( ) ;
846
- pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| dummy ) ;
842
+ pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| DUMMY_WILD_PAT ) ;
847
843
pats. extend ( after. iter ( ) . map ( |p| & * * p) ) ;
848
844
Some ( pats)
849
845
} ,
850
846
Slice ( length) if before. len ( ) + after. len ( ) <= length && slice. is_some ( ) => {
851
847
let mut pats: Vec < & Pat > = before. iter ( ) . map ( |p| & * * p) . collect ( ) ;
852
- pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| dummy ) ;
848
+ pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| DUMMY_WILD_PAT ) ;
853
849
pats. extend ( after. iter ( ) . map ( |p| & * * p) ) ;
854
850
Some ( pats)
855
851
} ,
@@ -919,7 +915,7 @@ fn check_fn(cx: &mut MatchCheckCtxt,
919
915
920
916
fn is_refutable < A > ( cx : & MatchCheckCtxt , pat : & Pat , refutable: |& Pat | -> A ) -> Option < A > {
921
917
let pats = Matrix ( vec ! ( vec!( pat) ) ) ;
922
- match is_useful ( cx, & pats, [ & DUMMY_WILD_PAT ] , ConstructWitness ) {
918
+ match is_useful ( cx, & pats, [ DUMMY_WILD_PAT ] , ConstructWitness ) {
923
919
UsefulWithWitness ( pats) => {
924
920
assert_eq ! ( pats. len( ) , 1 ) ;
925
921
Some ( refutable ( & * pats[ 0 ] ) )
0 commit comments