Skip to content

Commit 9a7834b

Browse files
canndrewalexcrichton
authored andcommitted
Remove use of ptr::eq
1 parent 8ee6855 commit 9a7834b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/librustc_const_eval/check_match.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::ptr;
1211
use _match::{MatchCheckCtxt, Matrix, expand_pattern, is_useful};
1312
use _match::Usefulness::*;
1413
use _match::WitnessPreference::*;
@@ -274,7 +273,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
274273
let mut seen = Matrix::empty();
275274
let mut catchall = None;
276275
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() {
278277
for &(pat, hir_pat) in pats {
279278
let v = vec![pat];
280279

@@ -305,17 +304,23 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
305304
let span = first_pat.0.span;
306305

307306
// 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!(),
319324
}
320325
},
321326

0 commit comments

Comments
 (0)