|
8 | 8 | // option. This file may not be copied, modified, or distributed |
9 | 9 | // except according to those terms. |
10 | 10 |
|
11 | | -use std::ptr; |
12 | 11 | use _match::{MatchCheckCtxt, Matrix, expand_pattern, is_useful}; |
13 | 12 | use _match::Usefulness::*; |
14 | 13 | use _match::WitnessPreference::*; |
@@ -274,7 +273,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, |
274 | 273 | let mut seen = Matrix::empty(); |
275 | 274 | let mut catchall = None; |
276 | 275 | let mut printed_if_let_err = false; |
277 | | - for &(ref pats, guard) in arms { |
| 276 | + for (arm_index, &(ref pats, guard)) in arms.iter().enumerate() { |
278 | 277 | for &(pat, hir_pat) in pats { |
279 | 278 | let v = vec![pat]; |
280 | 279 |
|
@@ -305,17 +304,23 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, |
305 | 304 | let span = first_pat.0.span; |
306 | 305 |
|
307 | 306 | // check which arm we're on. |
308 | | - if ptr::eq(first_arm_pats, pats) { |
309 | | - let mut diagnostic = Diagnostic::new(Level::Warning, |
310 | | - "unreachable pattern"); |
311 | | - diagnostic.set_span(pat.span); |
312 | | - cx.tcx.sess.add_lint_diagnostic(lint::builtin::UNREACHABLE_PATTERNS, |
313 | | - hir_pat.id, diagnostic); |
314 | | - } else { |
315 | | - struct_span_err!(cx.tcx.sess, span, E0165, |
316 | | - "irrefutable while-let pattern") |
317 | | - .span_label(span, &format!("irrefutable pattern")) |
318 | | - .emit(); |
| 307 | + match arm_index { |
| 308 | + // The arm with the user-specified pattern. |
| 309 | + 0 => { |
| 310 | + let mut diagnostic = Diagnostic::new(Level::Warning, |
| 311 | + "unreachable pattern"); |
| 312 | + diagnostic.set_span(pat.span); |
| 313 | + cx.tcx.sess.add_lint_diagnostic(lint::builtin::UNREACHABLE_PATTERNS, |
| 314 | + hir_pat.id, diagnostic); |
| 315 | + }, |
| 316 | + // The arm with the wildcard pattern. |
| 317 | + 1 => { |
| 318 | + struct_span_err!(cx.tcx.sess, span, E0165, |
| 319 | + "irrefutable while-let pattern") |
| 320 | + .span_label(span, &format!("irrefutable pattern")) |
| 321 | + .emit(); |
| 322 | + }, |
| 323 | + _ => bug!(), |
319 | 324 | } |
320 | 325 | }, |
321 | 326 |
|
|
0 commit comments