@@ -1016,12 +1016,8 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
1016
1016
fn check_local ( cx : & mut MatchCheckCtxt , loc : & ast:: Local ) {
1017
1017
visit:: walk_local ( cx, loc) ;
1018
1018
1019
- let mut static_inliner = StaticInliner :: new ( cx. tcx , None ) ;
1020
- is_refutable ( cx, & * static_inliner. fold_pat ( loc. pat . clone ( ) ) , |pat| {
1021
- span_err ! ( cx. tcx. sess, loc. pat. span, E0005 ,
1022
- "refutable pattern in local binding: `{}` not covered" , pat_to_string( pat)
1023
- ) ;
1024
- } ) ;
1019
+ let pat = StaticInliner :: new ( cx. tcx , None ) . fold_pat ( loc. pat . clone ( ) ) ;
1020
+ check_irrefutable ( cx, & pat, false ) ;
1025
1021
1026
1022
// Check legality of move bindings and `@` patterns.
1027
1023
check_legality_of_move_bindings ( cx, false , slice:: ref_slice ( & loc. pat ) ) ;
@@ -1042,17 +1038,28 @@ fn check_fn(cx: &mut MatchCheckCtxt,
1042
1038
visit:: walk_fn ( cx, kind, decl, body, sp) ;
1043
1039
1044
1040
for input in & decl. inputs {
1045
- is_refutable ( cx, & * input. pat , |pat| {
1046
- span_err ! ( cx. tcx. sess, input. pat. span, E0005 ,
1047
- "refutable pattern in function argument: `{}` not covered" ,
1048
- pat_to_string( pat)
1049
- ) ;
1050
- } ) ;
1041
+ check_irrefutable ( cx, & input. pat , true ) ;
1051
1042
check_legality_of_move_bindings ( cx, false , slice:: ref_slice ( & input. pat ) ) ;
1052
1043
check_legality_of_bindings_in_at_patterns ( cx, & * input. pat ) ;
1053
1044
}
1054
1045
}
1055
1046
1047
+ fn check_irrefutable ( cx : & MatchCheckCtxt , pat : & Pat , is_fn_arg : bool ) {
1048
+ let origin = if is_fn_arg {
1049
+ "function argument"
1050
+ } else {
1051
+ "local binding"
1052
+ } ;
1053
+
1054
+ is_refutable ( cx, pat, |uncovered_pat| {
1055
+ span_err ! ( cx. tcx. sess, pat. span, E0005 ,
1056
+ "refutable pattern in {}: `{}` not covered" ,
1057
+ origin,
1058
+ pat_to_string( uncovered_pat) ,
1059
+ ) ;
1060
+ } ) ;
1061
+ }
1062
+
1056
1063
fn is_refutable < A , F > ( cx : & MatchCheckCtxt , pat : & Pat , refutable : F ) -> Option < A > where
1057
1064
F : FnOnce ( & Pat ) -> A ,
1058
1065
{
0 commit comments