diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index d148d2a0885ed..2fe4ae627c1dc 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -424,10 +424,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(); }, } } diff --git a/src/test/compile-fail/non-exhaustive-pattern-witness.rs b/src/test/compile-fail/non-exhaustive-pattern-witness.rs index 0b12a9acbcb9e..eba61ede8cb20 100644 --- a/src/test/compile-fail/non-exhaustive-pattern-witness.rs +++ b/src/test/compile-fail/non-exhaustive-pattern-witness.rs @@ -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) => () } }