diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-02-05 12:45:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-05 12:45:12 -0500 |
| commit | 4e67bf92e3fb1321325d375933c4c0d2b233fef9 (patch) | |
| tree | 4a166ae2d41de164050e4d4e1178269e365fd359 /src/librustc_const_eval | |
| parent | 13b8e4b4161dc0c4587ab8dadc31df252fb492cd (diff) | |
| parent | 7135d0ab944f0bfa5ef4cecfd1dfdd8a79647c53 (diff) | |
Rollup merge of #39526 - canndrew:uninhabited-while-let-fix, r=arielb1
Uninhabited while-let pattern fix This fix makes it so while-let with an unsatisfiable pattern raises a correct warning rather than an incorrect error.
Diffstat (limited to 'src/librustc_const_eval')
| -rw-r--r-- | src/librustc_const_eval/check_match.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index 0b1f2465a4d..6f33b4fad76 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -273,7 +273,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, let mut seen = Matrix::empty(); let mut catchall = None; let mut printed_if_let_err = false; - for &(ref pats, guard) in arms { + for (arm_index, &(ref pats, guard)) in arms.iter().enumerate() { for &(pat, hir_pat) in pats { let v = vec![pat]; @@ -302,10 +302,27 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, let &(ref first_arm_pats, _) = &arms[0]; let first_pat = &first_arm_pats[0]; let span = first_pat.0.span; - struct_span_err!(cx.tcx.sess, span, E0165, - "irrefutable while-let pattern") - .span_label(span, &format!("irrefutable pattern")) - .emit(); + + // check which arm we're on. + match arm_index { + // The arm with the user-specified pattern. + 0 => { + let mut diagnostic = Diagnostic::new(Level::Warning, + "unreachable pattern"); + diagnostic.set_span(pat.span); + cx.tcx.sess.add_lint_diagnostic( + lint::builtin::UNREACHABLE_PATTERNS, + hir_pat.id, diagnostic); + }, + // The arm with the wildcard pattern. + 1 => { + struct_span_err!(cx.tcx.sess, span, E0165, + "irrefutable while-let pattern") + .span_label(span, &format!("irrefutable pattern")) + .emit(); + }, + _ => bug!(), + } }, hir::MatchSource::ForLoopDesugar | |
