diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-27 09:08:10 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-27 15:12:47 -0700 |
| commit | c381752b0eed42bfac2ef6f91fc1ab0b31ce7f3d (patch) | |
| tree | 98601716779ce7b1713b62d00cbfaad0038d0fa9 | |
| parent | a1d719dad49f83ea3f49884330726453357bb0c6 (diff) | |
| parent | f16744ce521537346188f984fdc50ea6c7c6eda3 (diff) | |
| download | rust-c381752b0eed42bfac2ef6f91fc1ab0b31ce7f3d.tar.gz rust-c381752b0eed42bfac2ef6f91fc1ab0b31ce7f3d.zip | |
rollup merge of #18356 : jakub-/const-pattern-suptype
| -rw-r--r-- | src/librustc/middle/typeck/check/_match.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issue-18352.rs | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 14725c581c8..1dcd8c76f4b 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -74,7 +74,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { let const_did = tcx.def_map.borrow().get_copy(&pat.id).def_id(); let const_pty = ty::lookup_item_type(tcx, const_did); fcx.write_ty(pat.id, const_pty.ty); - demand::eqtype(fcx, pat.span, expected, const_pty.ty); + demand::suptype(fcx, pat.span, expected, const_pty.ty); } ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => { let typ = fcx.local_ty(pat.span, pat.id); diff --git a/src/test/run-pass/issue-18352.rs b/src/test/run-pass/issue-18352.rs new file mode 100644 index 00000000000..7878d698e52 --- /dev/null +++ b/src/test/run-pass/issue-18352.rs @@ -0,0 +1,22 @@ +// Copyright 2014 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. + +const X: &'static str = "12345"; + +fn test(s: String) -> bool { + match s.as_slice() { + X => true, + _ => false + } +} + +fn main() { + assert!(test("12345".to_string())); +} |
