Skip to content

Commit 359d388

Browse files
committed
---
yaml --- r: 274291 b: refs/heads/stable c: 48e8326 h: refs/heads/master i: 274289: ec72e3c 274287: 48ba7cf
1 parent 3a3926a commit 359d388

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 6100743842ace6db859edfeed9959ac941210c2b
32+
refs/heads/stable: 48e83268930e2d21ff8894dc2eb65767d5b858fe
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc/middle/check_match.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,10 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
368368
fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir::MatchSource) {
369369
match is_useful(cx, matrix, &[DUMMY_WILD_PAT], ConstructWitness) {
370370
UsefulWithWitness(pats) => {
371-
let witnesses = match &pats[..] {
372-
[] => vec![DUMMY_WILD_PAT],
373-
[p..] => {
374-
p.iter().map(|w| &**w ).collect()
375-
}
371+
let witnesses = if pats.is_empty() {
372+
vec![DUMMY_WILD_PAT]
373+
} else {
374+
pats.iter().map(|w| &**w ).collect()
376375
};
377376
match source {
378377
hir::MatchSource::ForLoopDesugar => {
@@ -392,10 +391,21 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
392391
_ => {
393392
let pattern_strings: Vec<_> = witnesses.iter().map(|w| {
394393
pat_to_string(w)
395-
}).take(10).collect();
394+
}).collect();
395+
let (tail, head) = pattern_strings.split_last().unwrap();
396+
const HEAD_LIMIT: usize = 9;
397+
let joined_patterns = match head.len() {
398+
0 => tail.clone(),
399+
1...HEAD_LIMIT => head.join("`, `") + "` and `" + tail,
400+
_ => {
401+
let head_iter = head.to_owned().into_iter();
402+
let truncated_head: Vec<_> = head_iter.take(HEAD_LIMIT).collect();
403+
truncated_head.join("`, `") + "`, … and `" + tail
404+
}
405+
};
396406
span_err!(cx.tcx.sess, sp, E0004,
397407
"non-exhaustive patterns: `{}` not covered",
398-
pattern_strings.join("`, `")
408+
joined_patterns
399409
);
400410
},
401411
}

branches/stable/src/test/compile-fail/non-exhaustive-pattern-witness.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ struct Foo {
1616
second: Option<[usize; 4]>
1717
}
1818

19-
enum Color {
20-
Red,
21-
Green,
22-
CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
23-
}
24-
2519
fn struct_with_a_nested_enum_and_vector() {
2620
match (Foo { first: true, second: None }) {
2721
//~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
@@ -32,13 +26,42 @@ fn struct_with_a_nested_enum_and_vector() {
3226
}
3327
}
3428

35-
fn enum_with_multiple_missing_variants() {
29+
enum Color {
30+
Red,
31+
Green,
32+
CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
33+
}
34+
35+
fn enum_with_two_missing_variants() {
3636
match Color::Red {
37-
//~^ ERROR non-exhaustive patterns: `Red`, `Green` not covered
37+
//~^ ERROR non-exhaustive patterns: `Red` and `Green` not covered
3838
Color::CustomRGBA { .. } => ()
3939
}
4040
}
4141

42+
enum Direction {
43+
North, East, South, West
44+
}
45+
46+
fn enum_with_three_or_more_missing_variants() {
47+
match Direction::North {
48+
//~^ ERROR non-exhaustive patterns: `East`, `South` and `West` not covered
49+
Direction::North => ()
50+
}
51+
}
52+
53+
enum ExcessiveEnum {
54+
First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth
55+
}
56+
57+
fn enum_with_excessive_missing_variants() {
58+
match ExcessiveEnum::First {
59+
//~^ ERROR `Sixth`, `Seventh`, `Eighth`, `Ninth`, `Tenth`, … and `Twelfth` not covered
60+
61+
ExcessiveEnum::First => ()
62+
}
63+
}
64+
4265
fn enum_struct_variant() {
4366
match Color::Red {
4467
//~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered

0 commit comments

Comments
 (0)