@@ -863,13 +863,17 @@ fn default(cx: &MatchCheckCtxt, r: &[@Pat]) -> Option<Vec<@Pat> > {
863
863
864
864
fn check_local ( cx : & mut MatchCheckCtxt , loc : & Local ) {
865
865
visit:: walk_local ( cx, loc, ( ) ) ;
866
- if is_refutable ( cx, loc. pat ) {
867
- let name = match loc. source {
868
- LocalLet => "local" ,
869
- LocalFor => "`for` loop"
870
- } ;
871
866
872
- cx. tcx . sess . span_err ( loc. pat . span ,
867
+ let name = match loc. source {
868
+ LocalLet => "local" ,
869
+ LocalFor => "`for` loop"
870
+ } ;
871
+
872
+ let mut spans = vec ! [ ] ;
873
+ find_refutable ( cx, loc. pat , & mut spans) ;
874
+
875
+ for span in spans. iter ( ) {
876
+ cx. tcx . sess . span_err ( * span,
873
877
format ! ( "refutable pattern in {} binding" , name) . as_slice ( ) ) ;
874
878
}
875
879
@@ -884,53 +888,65 @@ fn check_fn(cx: &mut MatchCheckCtxt,
884
888
sp : Span ) {
885
889
visit:: walk_fn ( cx, kind, decl, body, sp, ( ) ) ;
886
890
for input in decl. inputs . iter ( ) {
887
- if is_refutable ( cx, input. pat ) {
888
- cx. tcx . sess . span_err ( input. pat . span ,
891
+ let mut spans = vec ! [ ] ;
892
+ find_refutable ( cx, input. pat , & mut spans) ;
893
+
894
+ for span in spans. iter ( ) {
895
+ cx. tcx . sess . span_err ( * span,
889
896
"refutable pattern in function argument" ) ;
890
897
}
891
898
}
892
899
}
893
900
894
- fn is_refutable ( cx : & MatchCheckCtxt , pat : & Pat ) -> bool {
901
+ fn find_refutable ( cx : & MatchCheckCtxt , pat : & Pat , spans : & mut Vec < Span > ) {
902
+ macro_rules! this_pattern {
903
+ ( ) => {
904
+ {
905
+ spans. push( pat. span) ;
906
+ return
907
+ }
908
+ }
909
+ }
895
910
let opt_def = cx. tcx . def_map . borrow ( ) . find_copy ( & pat. id ) ;
896
911
match opt_def {
897
912
Some ( DefVariant ( enum_id, _, _) ) => {
898
913
if ty:: enum_variants ( cx. tcx , enum_id) . len ( ) != 1 u {
899
- return true ;
914
+ this_pattern ! ( )
900
915
}
901
916
}
902
- Some ( DefStatic ( ..) ) => return true ,
917
+ Some ( DefStatic ( ..) ) => this_pattern ! ( ) ,
903
918
_ => ( )
904
919
}
905
920
906
921
match pat. node {
907
922
PatUniq ( sub) | PatRegion ( sub) | PatIdent ( _, _, Some ( sub) ) => {
908
- is_refutable ( cx, sub)
923
+ find_refutable ( cx, sub, spans )
909
924
}
910
- PatWild | PatWildMulti | PatIdent ( _, _, None ) => { false }
925
+ PatWild | PatWildMulti | PatIdent ( _, _, None ) => { }
911
926
PatLit ( lit) => {
912
927
match lit. node {
913
928
ExprLit ( lit) => {
914
929
match lit. node {
915
- LitNil => false , // `()`
916
- _ => true ,
930
+ LitNil => { } // `()`
931
+ _ => this_pattern ! ( ) ,
917
932
}
918
933
}
919
- _ => true ,
934
+ _ => this_pattern ! ( ) ,
920
935
}
921
936
}
922
- PatRange ( _, _) => { true }
937
+ PatRange ( _, _) => { this_pattern ! ( ) }
923
938
PatStruct ( _, ref fields, _) => {
924
- fields. iter ( ) . any ( |f| is_refutable ( cx, f. pat ) )
925
- }
926
- PatTup ( ref elts) => {
927
- elts. iter ( ) . any ( |elt| is_refutable ( cx, * elt) )
939
+ for f in fields. iter ( ) {
940
+ find_refutable ( cx, f. pat , spans) ;
941
+ }
928
942
}
929
- PatEnum ( _, Some ( ref args) ) => {
930
- args. iter ( ) . any ( |a| is_refutable ( cx, * a) )
943
+ PatTup ( ref elts) | PatEnum ( _, Some ( ref elts) ) => {
944
+ for elt in elts. iter ( ) {
945
+ find_refutable ( cx, * elt, spans)
946
+ }
931
947
}
932
- PatEnum ( _, _) => { false }
933
- PatVec ( ..) => { true }
948
+ PatEnum ( _, _) => { }
949
+ PatVec ( ..) => { this_pattern ! ( ) }
934
950
}
935
951
}
936
952
0 commit comments