@@ -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
@@ -309,12 +309,11 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
309
309
}
310
310
311
311
fn check_exhaustive ( cx : & MatchCheckCtxt , sp : Span , matrix : & Matrix ) {
312
- match is_useful ( cx, matrix, & [ & DUMMY_WILD_PAT ] , ConstructWitness ) {
312
+ match is_useful ( cx, matrix, & [ DUMMY_WILD_PAT ] , ConstructWitness ) {
313
313
UsefulWithWitness ( pats) => {
314
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
315
314
let witness = match pats. as_slice ( ) {
316
315
[ ref witness] => & * * witness,
317
- [ ] => & dummy ,
316
+ [ ] => DUMMY_WILD_PAT ,
318
317
_ => unreachable ! ( )
319
318
} ;
320
319
span_err ! ( cx. tcx. sess, sp, E0004 ,
@@ -568,9 +567,8 @@ fn is_useful(cx: &MatchCheckCtxt,
568
567
let arity = constructor_arity ( cx, & c, left_ty) ;
569
568
let mut result = {
570
569
let pat_slice = pats. as_slice ( ) ;
571
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
572
570
let subpats = Vec :: from_fn ( arity, |i| {
573
- pat_slice. get ( i) . map_or ( & dummy , |p| & * * p)
571
+ pat_slice. get ( i) . map_or ( DUMMY_WILD_PAT , |p| & * * p)
574
572
} ) ;
575
573
vec ! [ construct_witness( cx, & c, subpats, left_ty) ]
576
574
} ;
@@ -592,9 +590,8 @@ fn is_useful(cx: &MatchCheckCtxt,
592
590
} ) . collect ( ) ;
593
591
match is_useful ( cx, & matrix, v. tail ( ) , witness) {
594
592
UsefulWithWitness ( pats) => {
595
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
596
593
let arity = constructor_arity ( cx, & constructor, left_ty) ;
597
- let wild_pats = Vec :: from_elem ( arity, & dummy ) ;
594
+ let wild_pats = Vec :: from_elem ( arity, DUMMY_WILD_PAT ) ;
598
595
let enum_pat = construct_witness ( cx, & constructor, wild_pats, left_ty) ;
599
596
let mut new_pats = vec ! [ enum_pat] ;
600
597
new_pats. extend ( pats. into_iter ( ) ) ;
@@ -615,11 +612,10 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix,
615
612
v : & [ & Pat ] , ctor : Constructor , lty : ty:: t ,
616
613
witness : WitnessPreference ) -> Usefulness {
617
614
let arity = constructor_arity ( cx, & ctor, lty) ;
618
- let dummy = DUMMY_WILD_PAT . clone ( ) ;
619
615
let matrix = Matrix ( m. iter ( ) . filter_map ( |r| {
620
- specialize ( cx, r. as_slice ( ) , & dummy , & ctor, 0 u, arity)
616
+ specialize ( cx, r. as_slice ( ) , & ctor, 0 u, arity)
621
617
} ) . collect ( ) ) ;
622
- match specialize ( cx, v, & dummy , & ctor, 0 u, arity) {
618
+ match specialize ( cx, v, & ctor, 0 u, arity) {
623
619
Some ( v) => is_useful ( cx, & matrix, v. as_slice ( ) , witness) ,
624
620
None => NotUseful
625
621
}
@@ -741,15 +737,15 @@ fn range_covered_by_constructor(ctor: &Constructor,
741
737
/// different patterns.
742
738
/// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing
743
739
/// fields filled with wild patterns.
744
- pub fn specialize < ' a > ( cx : & MatchCheckCtxt , r : & [ & ' a Pat ] , dummy : & ' a Pat ,
740
+ pub fn specialize < ' a > ( cx : & MatchCheckCtxt , r : & [ & ' a Pat ] ,
745
741
constructor : & Constructor , col : uint , arity : uint ) -> Option < Vec < & ' a Pat > > {
746
742
let & Pat {
747
743
id : pat_id, node : ref node, span : pat_span
748
744
} = raw_pat ( r[ col] ) ;
749
745
let head: Option < Vec < & Pat > > = match node {
750
746
751
747
& PatWild ( _) =>
752
- Some ( Vec :: from_elem ( arity, dummy ) ) ,
748
+ Some ( Vec :: from_elem ( arity, DUMMY_WILD_PAT ) ) ,
753
749
754
750
& PatIdent ( _, _, _) => {
755
751
let opt_def = cx. tcx . def_map . borrow ( ) . find_copy ( & pat_id) ;
@@ -762,7 +758,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
762
758
} else {
763
759
None
764
760
} ,
765
- _ => Some ( Vec :: from_elem ( arity, dummy ) )
761
+ _ => Some ( Vec :: from_elem ( arity, DUMMY_WILD_PAT ) )
766
762
}
767
763
}
768
764
@@ -776,7 +772,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
776
772
DefVariant ( ..) | DefStruct ( ..) => {
777
773
Some ( match args {
778
774
& Some ( ref args) => args. iter ( ) . map ( |p| & * * p) . collect ( ) ,
779
- & None => Vec :: from_elem ( arity, dummy )
775
+ & None => Vec :: from_elem ( arity, DUMMY_WILD_PAT )
780
776
} )
781
777
}
782
778
_ => None
@@ -812,7 +808,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
812
808
let args = struct_fields. iter ( ) . map ( |sf| {
813
809
match pattern_fields. iter ( ) . find ( |f| f. ident . name == sf. name ) {
814
810
Some ( ref f) => & * f. pat ,
815
- _ => dummy
811
+ _ => DUMMY_WILD_PAT
816
812
}
817
813
} ) . collect ( ) ;
818
814
args
@@ -855,13 +851,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat,
855
851
// Fixed-length vectors.
856
852
Single => {
857
853
let mut pats: Vec < & Pat > = before. iter ( ) . map ( |p| & * * p) . collect ( ) ;
858
- pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| dummy ) ;
854
+ pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| DUMMY_WILD_PAT ) ;
859
855
pats. extend ( after. iter ( ) . map ( |p| & * * p) ) ;
860
856
Some ( pats)
861
857
} ,
862
858
Slice ( length) if before. len ( ) + after. len ( ) <= length && slice. is_some ( ) => {
863
859
let mut pats: Vec < & Pat > = before. iter ( ) . map ( |p| & * * p) . collect ( ) ;
864
- pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| dummy ) ;
860
+ pats. grow_fn ( arity - before. len ( ) - after. len ( ) , |_| DUMMY_WILD_PAT ) ;
865
861
pats. extend ( after. iter ( ) . map ( |p| & * * p) ) ;
866
862
Some ( pats)
867
863
} ,
@@ -931,7 +927,7 @@ fn check_fn(cx: &mut MatchCheckCtxt,
931
927
932
928
fn is_refutable < A > ( cx : & MatchCheckCtxt , pat : & Pat , refutable: |& Pat | -> A ) -> Option < A > {
933
929
let pats = Matrix ( vec ! ( vec!( pat) ) ) ;
934
- match is_useful ( cx, & pats, [ & DUMMY_WILD_PAT ] , ConstructWitness ) {
930
+ match is_useful ( cx, & pats, [ DUMMY_WILD_PAT ] , ConstructWitness ) {
935
931
UsefulWithWitness ( pats) => {
936
932
assert_eq ! ( pats. len( ) , 1 ) ;
937
933
Some ( refutable ( & * pats[ 0 ] ) )
0 commit comments