Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add help notes (and improve some error explanations too) #28231

Merged
merged 2 commits into from
Sep 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<i32> = box 0;
```
"##,

E0011: r##"
Expand Down Expand Up @@ -335,7 +342,6 @@ is not allowed.

If you really want global mutable state, try using `static mut` or a global
`UnsafeCell`.

"##,

E0018: r##"
Expand Down Expand Up @@ -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##"
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down