Skip to content

Commit 8c85a9d

Browse files
committed
Auto merge of #23313 - barosl:match-specialize-ice, r=jakub-
The arity of `ref x` is always 1, so it needs to be dereferenced before being compared with some other type whose arity is not 1. Fixes #23009.
2 parents 30e1f9a + edbc0e5 commit 8c85a9d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/librustc/middle/check_match.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ fn is_useful(cx: &MatchCheckCtxt,
646646
if rows[0].len() == 0 {
647647
return NotUseful;
648648
}
649+
assert!(rows.iter().all(|r| r.len() == v.len()));
649650
let real_pat = match rows.iter().find(|r| (*r)[0].id != DUMMY_NODE_ID) {
650651
Some(r) => raw_pat(r[0]),
651652
None if v.len() == 0 => return NotUseful,
@@ -654,7 +655,12 @@ fn is_useful(cx: &MatchCheckCtxt,
654655
let left_ty = if real_pat.id == DUMMY_NODE_ID {
655656
ty::mk_nil(cx.tcx)
656657
} else {
657-
ty::pat_ty(cx.tcx, &*real_pat)
658+
let left_ty = ty::pat_ty(cx.tcx, &*real_pat);
659+
660+
match real_pat.node {
661+
ast::PatIdent(ast::BindByRef(..), _, _) => ty::deref(left_ty, false).unwrap().ty,
662+
_ => left_ty,
663+
}
658664
};
659665

660666
let max_slice_length = rows.iter().filter_map(|row| match row[0].node {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// The arity of `ref x` is always 1. If the pattern is compared to some non-structural type whose
12+
// arity is always 0, an ICE occurs.
13+
//
14+
// Related issue: #23009
15+
16+
fn main() {
17+
let homura = [1, 2, 3];
18+
19+
match homura {
20+
[1, ref madoka, 3] => (),
21+
[1, 2, 3] => (), //~ ERROR unreachable pattern
22+
[_, _, _] => (),
23+
}
24+
}

0 commit comments

Comments
 (0)