From 092b6114c114edbe6f9930291aca74f549b2b64a Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 19 Feb 2013 00:56:02 +0900 Subject: [PATCH] add missing typecheck for const pattern match arm Issue #4968 --- src/librustc/middle/typeck/check/_match.rs | 1 + src/test/compile-fail/issue-4968.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/compile-fail/issue-4968.rs diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 95bed1140500d..bd099923f2bdb 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 0000000000000..315c2affe349c --- /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 or the MIT license +// , 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 `` but found `(int,int)` (expected integral variable but found tuple) +} +