Skip to content

Commit 76f7eee

Browse files
author
Jakub Wieczorek
committed
Fix #14393
String patterns should have a single constructor of arity 0.
1 parent 9dca26c commit 76f7eee

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/librustc/middle/check_match.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &ctor, pats: Vec<Gc<Pat>>, lty:
240240
&vec(_) => PatVec(pats, None, vec!()),
241241
_ => unreachable!()
242242
},
243+
ty::ty_str => PatWild,
243244
_ => {
244245
assert_eq!(pats.len(), 1);
245246
PatRegion(pats.get(0).clone())
@@ -479,6 +480,7 @@ fn constructor_arity(cx: &MatchCheckCtxt, ctor: &ctor, ty: ty::t) -> uint {
479480
vec(n) => n,
480481
_ => 0u
481482
},
483+
ty::ty_str => 0u,
482484
_ => 1u
483485
},
484486
ty::ty_enum(eid, _) => {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
fn main() {
12+
match ("", 1u) {
13+
(_, 42u) => (),
14+
("", _) => (),
15+
_ => ()
16+
}
17+
}

0 commit comments

Comments
 (0)