Skip to content

Commit 092b611

Browse files
committed
add missing typecheck for const pattern match arm
Issue #4968
1 parent a6945f2 commit 092b611

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/librustc/middle/typeck/check/_match.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
362362
ast::pat_ident(*) if pat_is_const(tcx.def_map, pat) => {
363363
let const_did = ast_util::def_id_of_def(tcx.def_map.get(&pat.id));
364364
let const_tpt = ty::lookup_item_type(tcx, const_did);
365+
demand::suptype(fcx, pat.span, expected, const_tpt.ty);
365366
fcx.write_ty(pat.id, const_tpt.ty);
366367
}
367368
ast::pat_ident(bm, name, sub) if pat_is_binding(tcx.def_map, pat) => {

src/test/compile-fail/issue-4968.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 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+
// Regression test for issue #4968
12+
13+
const A: (int,int) = (4,2);
14+
fn main() {
15+
match 42 { A => () } //~ ERROR mismatched types: expected `<VI0>` but found `(int,int)` (expected integral variable but found tuple)
16+
}
17+

0 commit comments

Comments
 (0)