@@ -863,9 +863,18 @@ 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
- cx. tcx . sess . span_err ( loc. pat . span ,
868
- "refutable pattern in local binding" ) ;
866
+
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,
877
+ format ! ( "refutable pattern in {} binding" , name) . as_slice ( ) ) ;
869
878
}
870
879
871
880
// Check legality of move bindings.
@@ -879,53 +888,65 @@ fn check_fn(cx: &mut MatchCheckCtxt,
879
888
sp : Span ) {
880
889
visit:: walk_fn ( cx, kind, decl, body, sp, ( ) ) ;
881
890
for input in decl. inputs . iter ( ) {
882
- if is_refutable ( cx, input. pat ) {
883
- 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,
884
896
"refutable pattern in function argument" ) ;
885
897
}
886
898
}
887
899
}
888
900
889
- 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
+ }
890
910
let opt_def = cx. tcx . def_map . borrow ( ) . find_copy ( & pat. id ) ;
891
911
match opt_def {
892
912
Some ( DefVariant ( enum_id, _, _) ) => {
893
913
if ty:: enum_variants ( cx. tcx , enum_id) . len ( ) != 1 u {
894
- return true ;
914
+ this_pattern ! ( )
895
915
}
896
916
}
897
- Some ( DefStatic ( ..) ) => return true ,
917
+ Some ( DefStatic ( ..) ) => this_pattern ! ( ) ,
898
918
_ => ( )
899
919
}
900
920
901
921
match pat. node {
902
922
PatUniq ( sub) | PatRegion ( sub) | PatIdent ( _, _, Some ( sub) ) => {
903
- is_refutable ( cx, sub)
923
+ find_refutable ( cx, sub, spans )
904
924
}
905
- PatWild | PatWildMulti | PatIdent ( _, _, None ) => { false }
925
+ PatWild | PatWildMulti | PatIdent ( _, _, None ) => { }
906
926
PatLit ( lit) => {
907
927
match lit. node {
908
928
ExprLit ( lit) => {
909
929
match lit. node {
910
- LitNil => false , // `()`
911
- _ => true ,
930
+ LitNil => { } // `()`
931
+ _ => this_pattern ! ( ) ,
912
932
}
913
933
}
914
- _ => true ,
934
+ _ => this_pattern ! ( ) ,
915
935
}
916
936
}
917
- PatRange ( _, _) => { true }
937
+ PatRange ( _, _) => { this_pattern ! ( ) }
918
938
PatStruct ( _, ref fields, _) => {
919
- fields. iter ( ) . any ( |f| is_refutable ( cx, f. pat ) )
920
- }
921
- PatTup ( ref elts) => {
922
- elts. iter ( ) . any ( |elt| is_refutable ( cx, * elt) )
939
+ for f in fields. iter ( ) {
940
+ find_refutable ( cx, f. pat , spans) ;
941
+ }
923
942
}
924
- PatEnum ( _, Some ( ref args) ) => {
925
- 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
+ }
926
947
}
927
- PatEnum ( _, _) => { false }
928
- PatVec ( ..) => { true }
948
+ PatEnum ( _, _) => { }
949
+ PatVec ( ..) => { this_pattern ! ( ) }
929
950
}
930
951
}
931
952
0 commit comments