Update E0004 to use labels

This commit is contained in:
TheZoq2 2016-08-05 21:00:23 +02:00
parent 9cf189701e
commit 422e0d590f
2 changed files with 14 additions and 2 deletions

View File

@ -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();
},
}
}

View File

@ -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 } => (),
@ -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 => ()
}
@ -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 => ()
}
}
@ -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 => ()
}
@ -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 } => (),
@ -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, _] => (),
@ -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) => ()
}
}