@@ -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
- struct MatchCheckCtxt {
31
+ pub 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
- fn check_expr ( v : & mut CheckMatchVisitor ,
67
+ pub fn check_expr ( v : & mut CheckMatchVisitor ,
68
68
cx : @MatchCheckCtxt ,
69
69
ex : @Expr ,
70
70
s : ( ) ) {
@@ -115,7 +115,7 @@ fn check_expr(v: &mut CheckMatchVisitor,
115
115
}
116
116
117
117
// Check for unreachable patterns
118
- fn check_arms ( cx : & MatchCheckCtxt , arms : & [ Arm ] ) {
118
+ pub 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 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
154
154
}
155
155
}
156
156
157
- fn raw_pat ( p : @Pat ) -> @Pat {
157
+ pub 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
- fn check_exhaustive ( cx : & MatchCheckCtxt , sp : Span , pats : ~[ @Pat ] ) {
164
+ pub 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 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: ~[@Pat]) {
209
209
cx. tcx . sess . span_err ( sp, msg) ;
210
210
}
211
211
212
- type matrix = ~[ ~[ @Pat ] ] ;
212
+ pub type matrix = ~[ ~[ @Pat ] ] ;
213
213
214
- enum useful { useful( ty:: t , ctor ) , useful_, not_useful }
214
+ pub enum useful { useful( ty:: t , ctor ) , useful_, not_useful }
215
215
216
216
#[ deriving( Eq ) ]
217
- enum ctor {
217
+ pub enum ctor {
218
218
single,
219
219
variant( DefId ) ,
220
220
val( const_val ) ,
@@ -235,7 +235,7 @@ 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
- fn is_useful ( cx : & MatchCheckCtxt , m : & matrix , v : & [ @Pat ] ) -> useful {
238
+ pub 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 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
314
314
}
315
315
}
316
316
317
- fn is_useful_specialized ( cx : & MatchCheckCtxt ,
317
+ pub fn is_useful_specialized ( cx : & MatchCheckCtxt ,
318
318
m : & matrix ,
319
319
v : & [ @Pat ] ,
320
320
ctor : ctor ,
@@ -330,7 +330,7 @@ fn is_useful_specialized(cx: &MatchCheckCtxt,
330
330
}
331
331
}
332
332
333
- fn pat_ctor_id ( cx : & MatchCheckCtxt , p : @Pat ) -> Option < ctor > {
333
+ pub 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 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
366
366
}
367
367
}
368
368
369
- fn is_wild ( cx : & MatchCheckCtxt , p : @Pat ) -> bool {
369
+ pub 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 @@ fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
380
380
}
381
381
}
382
382
383
- fn missing_ctor ( cx : & MatchCheckCtxt ,
383
+ pub fn missing_ctor ( cx : & MatchCheckCtxt ,
384
384
m : & matrix ,
385
385
left_ty : ty:: t )
386
386
-> Option < ctor > {
@@ -505,7 +505,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
505
505
}
506
506
}
507
507
508
- fn ctor_arity ( cx : & MatchCheckCtxt , ctor : & ctor , ty : ty:: t ) -> uint {
508
+ pub 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 @@ fn ctor_arity(cx: &MatchCheckCtxt, ctor: &ctor, ty: ty::t) -> uint {
528
528
}
529
529
}
530
530
531
- fn wild ( ) -> @Pat {
531
+ pub fn wild ( ) -> @Pat {
532
532
@Pat { id : 0 , node : PatWild , span : dummy_sp ( ) }
533
533
}
534
534
535
- fn specialize ( cx : & MatchCheckCtxt ,
535
+ pub fn specialize ( cx : & MatchCheckCtxt ,
536
536
r : & [ @Pat ] ,
537
537
ctor_id : & ctor ,
538
538
arity : uint ,
@@ -662,14 +662,15 @@ fn specialize(cx: &MatchCheckCtxt,
662
662
_ => None
663
663
}
664
664
}
665
- PatStruct ( _, ref pattern_fields , _) => {
665
+ PatStruct ( _, ref flds , _) => {
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
- 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 ) {
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 ) {
673
674
Some ( f) => f. pat ,
674
675
_ => wild ( )
675
676
}
@@ -699,7 +700,7 @@ fn specialize(cx: &MatchCheckCtxt,
699
700
}
700
701
}
701
702
let args = class_fields. iter ( ) . map ( |class_field| {
702
- match pattern_fields . iter ( ) . find ( |f|
703
+ match flds . iter ( ) . find ( |f|
703
704
f. ident . name == class_field. name ) {
704
705
Some ( f) => f. pat ,
705
706
_ => wild ( )
@@ -797,12 +798,12 @@ fn specialize(cx: &MatchCheckCtxt,
797
798
}
798
799
}
799
800
800
- fn default ( cx : & MatchCheckCtxt , r : & [ @Pat ] ) -> Option < ~[ @Pat ] > {
801
+ pub fn default ( cx : & MatchCheckCtxt , r : & [ @Pat ] ) -> Option < ~[ @Pat ] > {
801
802
if is_wild ( cx, r[ 0 ] ) { Some ( r. tail ( ) . to_owned ( ) ) }
802
803
else { None }
803
804
}
804
805
805
- fn check_local ( v : & mut CheckMatchVisitor ,
806
+ pub fn check_local ( v : & mut CheckMatchVisitor ,
806
807
cx : & MatchCheckCtxt ,
807
808
loc : @Local ,
808
809
s : ( ) ) {
@@ -816,7 +817,7 @@ fn check_local(v: &mut CheckMatchVisitor,
816
817
check_legality_of_move_bindings ( cx, false , [ loc. pat ] ) ;
817
818
}
818
819
819
- fn check_fn ( v : & mut CheckMatchVisitor ,
820
+ pub fn check_fn ( v : & mut CheckMatchVisitor ,
820
821
cx : & MatchCheckCtxt ,
821
822
kind : & visit:: fn_kind ,
822
823
decl : & fn_decl ,
@@ -833,7 +834,7 @@ fn check_fn(v: &mut CheckMatchVisitor,
833
834
}
834
835
}
835
836
836
- fn is_refutable ( cx : & MatchCheckCtxt , pat : & Pat ) -> bool {
837
+ pub fn is_refutable ( cx : & MatchCheckCtxt , pat : & Pat ) -> bool {
837
838
match cx. tcx . def_map . find ( & pat. id ) {
838
839
Some ( & DefVariant ( enum_id, _, _) ) => {
839
840
if ty:: enum_variants ( cx. tcx , enum_id) . len ( ) != 1 u {
@@ -871,7 +872,7 @@ fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool {
871
872
872
873
// Legality of move bindings checking
873
874
874
- fn check_legality_of_move_bindings ( cx : & MatchCheckCtxt ,
875
+ pub fn check_legality_of_move_bindings ( cx : & MatchCheckCtxt ,
875
876
has_guard : bool ,
876
877
pats : & [ @Pat ] ) {
877
878
let tcx = cx. tcx ;
0 commit comments