From ec4ba272b00c7a7cae537a73d52f692a1a943e1b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 4 Sep 2015 18:09:16 +0200 Subject: [PATCH 1/2] Add span_help for E0002 --- src/librustc/diagnostics.rs | 2 +- src/librustc/middle/check_match.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 696b38219f440..61cc63fa31771 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -44,7 +44,7 @@ E0002: r##" This error indicates that an empty match expression is invalid because the type it is matching on is non-empty (there exist values of this type). In safe code it is impossible to create an instance of an empty type, so empty match -expressions are almost never desired. This error is typically fixed by adding +expressions are almost never desired. This error is typically fixed by adding one or more cases to the match expression. An example of an empty type is `enum Empty { }`. So, the following will work: diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index d0111860b4406..767eab69733c3 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -218,6 +218,9 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) { span_err!(cx.tcx.sess, ex.span, E0002, "non-exhaustive patterns: type {} is non-empty", pat_ty); + span_help!(cx.tcx.sess, ex.span, + "Please ensure that all possible cases are being handled; \ + possibly adding wildcards or more match arms."); } // If the type *is* empty, it's vacuously exhaustive return; From 771ab35c3d3ee684a0d938fe50b1dc21edbca621 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 4 Sep 2015 18:11:51 +0200 Subject: [PATCH 2/2] Add erroneous code example for E0010 --- src/librustc/diagnostics.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 61cc63fa31771..91845e916d4d4 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -218,7 +218,14 @@ match x { E0010: r##" The value of statics and constants must be known at compile time, and they live for the entire lifetime of a program. Creating a boxed value allocates memory on -the heap at runtime, and therefore cannot be done at compile time. +the heap at runtime, and therefore cannot be done at compile time. Erroneous +code example: + +``` +#![feature(box_syntax)] + +const CON : Box = box 0; +``` "##, E0011: r##" @@ -335,7 +342,6 @@ is not allowed. If you really want global mutable state, try using `static mut` or a global `UnsafeCell`. - "##, E0018: r##" @@ -399,7 +405,13 @@ fn main() { E0020: r##" This error indicates that an attempt was made to divide by zero (or take the -remainder of a zero divisor) in a static or constant expression. +remainder of a zero divisor) in a static or constant expression. Erroneous +code example: + +``` +const X: i32 = 42 / 0; +// error: attempted to divide by zero in a constant expression +``` "##, E0022: r##"