Skip to content

Commit f16744c

Browse files
author
Jakub Bukaj
committed
Fix a typecheck regression with constant borrowed pointers in patterns
Change the eqtype relationship to be a suptype relationship instead. Fixes #18350. Fixes #18352.
1 parent 80e5fe1 commit f16744c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
7474
let const_did = tcx.def_map.borrow().get_copy(&pat.id).def_id();
7575
let const_pty = ty::lookup_item_type(tcx, const_did);
7676
fcx.write_ty(pat.id, const_pty.ty);
77-
demand::eqtype(fcx, pat.span, expected, const_pty.ty);
77+
demand::suptype(fcx, pat.span, expected, const_pty.ty);
7878
}
7979
ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => {
8080
let typ = fcx.local_ty(pat.span, pat.id);

src/test/run-pass/issue-18352.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 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+
const X: &'static str = "12345";
12+
13+
fn test(s: String) -> bool {
14+
match s.as_slice() {
15+
X => true,
16+
_ => false
17+
}
18+
}
19+
20+
fn main() {
21+
assert!(test("12345".to_string()));
22+
}

0 commit comments

Comments
 (0)