From 19512be11376a17f6c73fb28facad1f0d9f9cefb Mon Sep 17 00:00:00 2001 From: mitaa Date: Sun, 26 Jul 2015 00:01:28 +0200 Subject: [PATCH] Sidestep warning about repeated E0005 `span_err!` invocation. Fixes #27279 --- src/librustc/middle/check_match.rs | 31 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index d1467b67310..7c02045d083 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -1016,12 +1016,8 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], fn check_local(cx: &mut MatchCheckCtxt, loc: &ast::Local) { visit::walk_local(cx, loc); - let mut static_inliner = StaticInliner::new(cx.tcx, None); - is_refutable(cx, &*static_inliner.fold_pat(loc.pat.clone()), |pat| { - span_err!(cx.tcx.sess, loc.pat.span, E0005, - "refutable pattern in local binding: `{}` not covered", pat_to_string(pat) - ); - }); + let pat = StaticInliner::new(cx.tcx, None).fold_pat(loc.pat.clone()); + check_irrefutable(cx, &pat, false); // Check legality of move bindings and `@` patterns. check_legality_of_move_bindings(cx, false, slice::ref_slice(&loc.pat)); @@ -1042,17 +1038,28 @@ fn check_fn(cx: &mut MatchCheckCtxt, visit::walk_fn(cx, kind, decl, body, sp); for input in &decl.inputs { - is_refutable(cx, &*input.pat, |pat| { - span_err!(cx.tcx.sess, input.pat.span, E0005, - "refutable pattern in function argument: `{}` not covered", - pat_to_string(pat) - ); - }); + check_irrefutable(cx, &input.pat, true); check_legality_of_move_bindings(cx, false, slice::ref_slice(&input.pat)); check_legality_of_bindings_in_at_patterns(cx, &*input.pat); } } +fn check_irrefutable(cx: &MatchCheckCtxt, pat: &Pat, is_fn_arg: bool) { + let origin = if is_fn_arg { + "function argument" + } else { + "local binding" + }; + + is_refutable(cx, pat, |uncovered_pat| { + span_err!(cx.tcx.sess, pat.span, E0005, + "refutable pattern in {}: `{}` not covered", + origin, + pat_to_string(uncovered_pat), + ); + }); +} + fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat, refutable: F) -> Option where F: FnOnce(&Pat) -> A, {