Skip to content

Commit 19512be

Browse files
committed
Sidestep warning about repeated E0005 span_err! invocation.
Fixes #27279
1 parent adfdbc4 commit 19512be

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/librustc/middle/check_match.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,12 +1016,8 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
10161016
fn check_local(cx: &mut MatchCheckCtxt, loc: &ast::Local) {
10171017
visit::walk_local(cx, loc);
10181018

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);
10251021

10261022
// Check legality of move bindings and `@` patterns.
10271023
check_legality_of_move_bindings(cx, false, slice::ref_slice(&loc.pat));
@@ -1042,17 +1038,28 @@ fn check_fn(cx: &mut MatchCheckCtxt,
10421038
visit::walk_fn(cx, kind, decl, body, sp);
10431039

10441040
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);
10511042
check_legality_of_move_bindings(cx, false, slice::ref_slice(&input.pat));
10521043
check_legality_of_bindings_in_at_patterns(cx, &*input.pat);
10531044
}
10541045
}
10551046

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+
10561063
fn is_refutable<A, F>(cx: &MatchCheckCtxt, pat: &Pat, refutable: F) -> Option<A> where
10571064
F: FnOnce(&Pat) -> A,
10581065
{

0 commit comments

Comments
 (0)