Skip to content

Commit 43ddd60

Browse files
committed
---
yaml --- r: 274292 b: refs/heads/stable c: 70692ce h: refs/heads/master
1 parent 359d388 commit 43ddd60

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
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: 48e83268930e2d21ff8894dc2eb65767d5b858fe
32+
refs/heads/stable: 70692ce27953c91800549d6929b24e32b003c4f0
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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,21 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
392392
let pattern_strings: Vec<_> = witnesses.iter().map(|w| {
393393
pat_to_string(w)
394394
}).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,
395+
const LIMIT: usize = 3;
396+
let joined_patterns = match pattern_strings.len() {
397+
0 => unreachable!(),
398+
1 => format!("`{}`", pattern_strings[0]),
399+
2...LIMIT => {
400+
let (tail, head) = pattern_strings.split_last().unwrap();
401+
format!("`{}`", head.join("`, `") + "` and `" + tail)
402+
},
400403
_ => {
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+
let (head, tail) = pattern_strings.split_at(LIMIT);
405+
format!("`{}` and {} more", head.join("`, `"), tail.len())
404406
}
405407
};
406408
span_err!(cx.tcx.sess, sp, E0004,
407-
"non-exhaustive patterns: `{}` not covered",
409+
"non-exhaustive patterns: {} not covered",
408410
joined_patterns
409411
);
410412
},

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ enum Color {
3232
CustomRGBA { a: bool, r: u8, g: u8, b: u8 }
3333
}
3434

35-
fn enum_with_two_missing_variants() {
35+
fn enum_with_single_missing_variant() {
3636
match Color::Red {
37-
//~^ ERROR non-exhaustive patterns: `Red` and `Green` not covered
38-
Color::CustomRGBA { .. } => ()
37+
//~^ ERROR non-exhaustive patterns: `Red` not covered
38+
Color::CustomRGBA { .. } => (),
39+
Color::Green => ()
3940
}
4041
}
4142

4243
enum Direction {
4344
North, East, South, West
4445
}
4546

46-
fn enum_with_three_or_more_missing_variants() {
47+
fn enum_with_multiple_missing_variants() {
4748
match Direction::North {
4849
//~^ ERROR non-exhaustive patterns: `East`, `South` and `West` not covered
4950
Direction::North => ()
@@ -56,7 +57,7 @@ enum ExcessiveEnum {
5657

5758
fn enum_with_excessive_missing_variants() {
5859
match ExcessiveEnum::First {
59-
//~^ ERROR `Sixth`, `Seventh`, `Eighth`, `Ninth`, `Tenth`, … and `Twelfth` not covered
60+
//~^ ERROR `Second`, `Third`, `Fourth` and 8 more not covered
6061

6162
ExcessiveEnum::First => ()
6263
}

0 commit comments

Comments
 (0)