about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeong YunWon <jeong@youknowone.org>2013-02-19 00:56:02 +0900
committerJeong YunWon <jeong@youknowone.org>2013-02-19 00:56:02 +0900
commit092b6114c114edbe6f9930291aca74f549b2b64a (patch)
treef11db99dcbb05a27b4228c4e0ab69da2c0008768
parenta6945f2a45d56ef692cd8f2955dcef4e4c10d50a (diff)
downloadrust-092b6114c114edbe6f9930291aca74f549b2b64a.tar.gz
rust-092b6114c114edbe6f9930291aca74f549b2b64a.zip
add missing typecheck for const pattern match arm
Issue #4968
-rw-r--r--src/librustc/middle/typeck/check/_match.rs1
-rw-r--r--src/test/compile-fail/issue-4968.rs17
2 files changed, 18 insertions, 0 deletions
diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs
index 95bed114050..bd099923f2b 100644
--- a/src/librustc/middle/typeck/check/_match.rs
+++ b/src/librustc/middle/typeck/check/_match.rs
@@ -362,6 +362,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
       ast::pat_ident(*) if pat_is_const(tcx.def_map, pat) => {
         let const_did = ast_util::def_id_of_def(tcx.def_map.get(&pat.id));
         let const_tpt = ty::lookup_item_type(tcx, const_did);
+        demand::suptype(fcx, pat.span, expected, const_tpt.ty);
         fcx.write_ty(pat.id, const_tpt.ty);
       }
       ast::pat_ident(bm, name, sub) if pat_is_binding(tcx.def_map, pat) => {
diff --git a/src/test/compile-fail/issue-4968.rs b/src/test/compile-fail/issue-4968.rs
new file mode 100644
index 00000000000..315c2affe34
--- /dev/null
+++ b/src/test/compile-fail/issue-4968.rs
@@ -0,0 +1,17 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Regression test for issue #4968
+
+const A: (int,int) = (4,2);
+fn main() {
+    match 42 { A => () } //~ ERROR mismatched types: expected `<VI0>` but found `(int,int)` (expected integral variable but found tuple)
+}
+