@@ -28,7 +28,7 @@ use syntax::codemap::{Span, dummy_sp, Spanned};
28
28
use syntax:: visit;
29
29
use syntax:: visit:: { Visitor , fn_kind} ;
30
30
31
- pub struct MatchCheckCtxt {
31
+ struct MatchCheckCtxt {
32
32
tcx : ty:: ctxt ,
33
33
method_map : method_map ,
34
34
moves_map : moves:: MovesMap
@@ -64,7 +64,7 @@ pub fn check_crate(tcx: ty::ctxt,
64
64
tcx. sess . abort_if_errors ( ) ;
65
65
}
66
66
67
- pub fn check_expr ( v : & mut CheckMatchVisitor ,
67
+ fn check_expr ( v : & mut CheckMatchVisitor ,
68
68
cx : @MatchCheckCtxt ,
69
69
ex : @Expr ,
70
70
s : ( ) ) {
@@ -115,7 +115,7 @@ pub fn check_expr(v: &mut CheckMatchVisitor,
115
115
}
116
116
117
117
// Check for unreachable patterns
118
- pub fn check_arms ( cx : & MatchCheckCtxt , arms : & [ Arm ] ) {
118
+ fn check_arms ( cx : & MatchCheckCtxt , arms : & [ Arm ] ) {
119
119
let mut seen = ~[ ] ;
120
120
for arm in arms. iter ( ) {
121
121
for pat in arm. pats . iter ( ) {
@@ -154,14 +154,14 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
154
154
}
155
155
}
156
156
157
- pub fn raw_pat ( p : @Pat ) -> @Pat {
157
+ fn raw_pat ( p : @Pat ) -> @Pat {
158
158
match p. node {
159
159
PatIdent ( _, _, Some ( s) ) => { raw_pat ( s) }
160
160
_ => { p }
161
161
}
162
162
}
163
163
164
- pub fn check_exhaustive ( cx : & MatchCheckCtxt , sp : Span , pats : ~[ @Pat ] ) {
164
+ fn check_exhaustive ( cx : & MatchCheckCtxt , sp : Span , pats : ~[ @Pat ] ) {
165
165
assert ! ( ( !pats. is_empty( ) ) ) ;
166
166
let ext = match is_useful ( cx, & pats. map ( |p| ~[ * p] ) , [ wild ( ) ] ) {
167
167
not_useful => {
@@ -209,12 +209,12 @@ pub fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: ~[@Pat]) {
209
209
cx. tcx . sess . span_err ( sp, msg) ;
210
210
}
211
211
212
- pub type matrix = ~[ ~[ @Pat ] ] ;
212
+ type matrix = ~[ ~[ @Pat ] ] ;
213
213
214
- pub enum useful { useful( ty:: t , ctor ) , useful_, not_useful }
214
+ enum useful { useful( ty:: t , ctor ) , useful_, not_useful }
215
215
216
216
#[ deriving( Eq ) ]
217
- pub enum ctor {
217
+ enum ctor {
218
218
single,
219
219
variant( DefId ) ,
220
220
val( const_val ) ,
@@ -235,7 +235,7 @@ pub enum ctor {
235
235
236
236
// Note: is_useful doesn't work on empty types, as the paper notes.
237
237
// So it assumes that v is non-empty.
238
- pub fn is_useful ( cx : & MatchCheckCtxt , m : & matrix , v : & [ @Pat ] ) -> useful {
238
+ fn is_useful ( cx : & MatchCheckCtxt , m : & matrix , v : & [ @Pat ] ) -> useful {
239
239
if m. len ( ) == 0 u { return useful_; }
240
240
if m[ 0 ] . len ( ) == 0 u { return not_useful; }
241
241
let real_pat = match m. iter ( ) . find ( |r| r[ 0 ] . id != 0 ) {
@@ -314,7 +314,7 @@ pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
314
314
}
315
315
}
316
316
317
- pub fn is_useful_specialized ( cx : & MatchCheckCtxt ,
317
+ fn is_useful_specialized ( cx : & MatchCheckCtxt ,
318
318
m : & matrix ,
319
319
v : & [ @Pat ] ,
320
320
ctor : ctor ,
@@ -330,7 +330,7 @@ pub fn is_useful_specialized(cx: &MatchCheckCtxt,
330
330
}
331
331
}
332
332
333
- pub fn pat_ctor_id ( cx : & MatchCheckCtxt , p : @Pat ) -> Option < ctor > {
333
+ fn pat_ctor_id ( cx : & MatchCheckCtxt , p : @Pat ) -> Option < ctor > {
334
334
let pat = raw_pat ( p) ;
335
335
match pat. node {
336
336
PatWild => { None }
@@ -366,7 +366,7 @@ pub fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
366
366
}
367
367
}
368
368
369
- pub fn is_wild ( cx : & MatchCheckCtxt , p : @Pat ) -> bool {
369
+ fn is_wild ( cx : & MatchCheckCtxt , p : @Pat ) -> bool {
370
370
let pat = raw_pat ( p) ;
371
371
match pat. node {
372
372
PatWild => { true }
@@ -380,7 +380,7 @@ pub fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
380
380
}
381
381
}
382
382
383
- pub fn missing_ctor ( cx : & MatchCheckCtxt ,
383
+ fn missing_ctor ( cx : & MatchCheckCtxt ,
384
384
m : & matrix ,
385
385
left_ty : ty:: t )
386
386
-> Option < ctor > {
@@ -505,7 +505,7 @@ pub fn missing_ctor(cx: &MatchCheckCtxt,
505
505
}
506
506
}
507
507
508
- pub fn ctor_arity ( cx : & MatchCheckCtxt , ctor : & ctor , ty : ty:: t ) -> uint {
508
+ fn ctor_arity ( cx : & MatchCheckCtxt , ctor : & ctor , ty : ty:: t ) -> uint {
509
509
match ty:: get ( ty) . sty {
510
510
ty:: ty_tup( ref fs) => fs. len ( ) ,
511
511
ty:: ty_box( _) | ty:: ty_uniq( _) | ty:: ty_rptr( * ) => 1 u,
@@ -528,11 +528,11 @@ pub fn ctor_arity(cx: &MatchCheckCtxt, ctor: &ctor, ty: ty::t) -> uint {
528
528
}
529
529
}
530
530
531
- pub fn wild ( ) -> @Pat {
531
+ fn wild ( ) -> @Pat {
532
532
@Pat { id : 0 , node : PatWild , span : dummy_sp ( ) }
533
533
}
534
534
535
- pub fn specialize ( cx : & MatchCheckCtxt ,
535
+ fn specialize ( cx : & MatchCheckCtxt ,
536
536
r : & [ @Pat ] ,
537
537
ctor_id : & ctor ,
538
538
arity : uint ,
@@ -662,15 +662,14 @@ pub fn specialize(cx: &MatchCheckCtxt,
662
662
_ => None
663
663
}
664
664
}
665
- PatStruct ( _, ref flds , _) => {
665
+ PatStruct ( _, ref pattern_fields , _) => {
666
666
// Is this a struct or an enum variant?
667
667
match cx. tcx . def_map . get_copy ( & pat_id) {
668
668
DefVariant ( _, variant_id, _) => {
669
669
if variant ( variant_id) == * ctor_id {
670
- // FIXME #4731: Is this right? --pcw
671
- let args = flds. map ( |ty_field| {
672
- match flds. iter ( ) . find ( |f|
673
- f. ident == ty_field. ident ) {
670
+ let struct_fields = ty:: lookup_struct_fields ( cx. tcx , variant_id) ;
671
+ let args = struct_fields. map ( |sf| {
672
+ match pattern_fields. iter ( ) . find ( |f| f. ident . name == sf. name ) {
674
673
Some ( f) => f. pat ,
675
674
_ => wild ( )
676
675
}
@@ -700,7 +699,7 @@ pub fn specialize(cx: &MatchCheckCtxt,
700
699
}
701
700
}
702
701
let args = class_fields. iter ( ) . map ( |class_field| {
703
- match flds . iter ( ) . find ( |f|
702
+ match pattern_fields . iter ( ) . find ( |f|
704
703
f. ident . name == class_field. name ) {
705
704
Some ( f) => f. pat ,
706
705
_ => wild ( )
@@ -798,12 +797,12 @@ pub fn specialize(cx: &MatchCheckCtxt,
798
797
}
799
798
}
800
799
801
- pub fn default ( cx : & MatchCheckCtxt , r : & [ @Pat ] ) -> Option < ~[ @Pat ] > {
800
+ fn default ( cx : & MatchCheckCtxt , r : & [ @Pat ] ) -> Option < ~[ @Pat ] > {
802
801
if is_wild ( cx, r[ 0 ] ) { Some ( r. tail ( ) . to_owned ( ) ) }
803
802
else { None }
804
803
}
805
804
806
- pub fn check_local ( v : & mut CheckMatchVisitor ,
805
+ fn check_local ( v : & mut CheckMatchVisitor ,
807
806
cx : & MatchCheckCtxt ,
808
807
loc : @Local ,
809
808
s : ( ) ) {
@@ -817,7 +816,7 @@ pub fn check_local(v: &mut CheckMatchVisitor,
817
816
check_legality_of_move_bindings ( cx, false , [ loc. pat ] ) ;
818
817
}
819
818
820
- pub fn check_fn ( v : & mut CheckMatchVisitor ,
819
+ fn check_fn ( v : & mut CheckMatchVisitor ,
821
820
cx : & MatchCheckCtxt ,
822
821
kind : & visit:: fn_kind ,
823
822
decl : & fn_decl ,
@@ -834,7 +833,7 @@ pub fn check_fn(v: &mut CheckMatchVisitor,
834
833
}
835
834
}
836
835
837
- pub fn is_refutable ( cx : & MatchCheckCtxt , pat : & Pat ) -> bool {
836
+ fn is_refutable ( cx : & MatchCheckCtxt , pat : & Pat ) -> bool {
838
837
match cx. tcx . def_map . find ( & pat. id ) {
839
838
Some ( & DefVariant ( enum_id, _, _) ) => {
840
839
if ty:: enum_variants ( cx. tcx , enum_id) . len ( ) != 1 u {
@@ -872,7 +871,7 @@ pub fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool {
872
871
873
872
// Legality of move bindings checking
874
873
875
- pub fn check_legality_of_move_bindings ( cx : & MatchCheckCtxt ,
874
+ fn check_legality_of_move_bindings ( cx : & MatchCheckCtxt ,
876
875
has_guard : bool ,
877
876
pats : & [ @Pat ] ) {
878
877
let tcx = cx. tcx ;
0 commit comments