Skip to content

Commit

Permalink
Update E0004 to use labels
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZoq2 committed Aug 5, 2016
1 parent 9cf1897 commit 422e0d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/librustc_const_eval/check_match.rs
Expand Up @@ -423,10 +423,15 @@ fn check_exhaustive<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>,
format!("`{}` and {} more", head.join("`, `"), tail.len())
}
};
span_err!(cx.tcx.sess, sp, E0004,

let label_text = match pattern_strings.len(){
1 => format!("pattern {} not covered", joined_patterns),
_ => format!("patterns {} not covered", joined_patterns)
};
struct_span_err!(cx.tcx.sess, sp, E0004,
"non-exhaustive patterns: {} not covered",
joined_patterns
);
).span_label(sp, &label_text).emit();
},
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/compile-fail/non-exhaustive-pattern-witness.rs
Expand Up @@ -19,6 +19,7 @@ struct Foo {
fn struct_with_a_nested_enum_and_vector() {
match (Foo { first: true, second: None }) {
//~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
//~| NOTE pattern `Foo { first: false, second: Some([_, _, _, _]) }` not covered
Foo { first: true, second: None } => (),
Foo { first: true, second: Some(_) } => (),
Foo { first: false, second: None } => (),
Expand All @@ -35,6 +36,7 @@ enum Color {
fn enum_with_single_missing_variant() {
match Color::Red {
//~^ ERROR non-exhaustive patterns: `Red` not covered
//~| NOTE pattern `Red` not covered
Color::CustomRGBA { .. } => (),
Color::Green => ()
}
Expand All @@ -47,6 +49,7 @@ enum Direction {
fn enum_with_multiple_missing_variants() {
match Direction::North {
//~^ ERROR non-exhaustive patterns: `East`, `South` and `West` not covered
//~| NOTE patterns `East`, `South` and `West` not covered
Direction::North => ()
}
}
Expand All @@ -58,6 +61,7 @@ enum ExcessiveEnum {
fn enum_with_excessive_missing_variants() {
match ExcessiveEnum::First {
//~^ ERROR `Second`, `Third`, `Fourth` and 8 more not covered
//~| NOTE patterns `Second`, `Third`, `Fourth` and 8 more not covered

ExcessiveEnum::First => ()
}
Expand All @@ -66,6 +70,7 @@ fn enum_with_excessive_missing_variants() {
fn enum_struct_variant() {
match Color::Red {
//~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
//~| NOTE pattern `CustomRGBA { a: true, .. }` not covered
Color::Red => (),
Color::Green => (),
Color::CustomRGBA { a: false, r: _, g: _, b: 0 } => (),
Expand All @@ -82,6 +87,7 @@ fn vectors_with_nested_enums() {
let x: &'static [Enum] = &[Enum::First, Enum::Second(false)];
match *x {
//~^ ERROR non-exhaustive patterns: `[Second(true), Second(false)]` not covered
//~| NOTE pattern `[Second(true), Second(false)]` not covered
[] => (),
[_] => (),
[Enum::First, _] => (),
Expand All @@ -95,6 +101,7 @@ fn vectors_with_nested_enums() {
fn missing_nil() {
match ((), false) {
//~^ ERROR non-exhaustive patterns: `((), false)` not covered
//~| NOTE pattern `((), false)` not covered
((), true) => ()
}
}
Expand Down

0 comments on commit 422e0d5

Please sign in to comment.