]> git.lizzy.rs Git - rust.git/commit
auto merge of #15336 : jakub-/rust/diagnostics, r=brson
authorbors <bors@rust-lang.org>
Thu, 10 Jul 2014 23:26:39 +0000 (23:26 +0000)
committerbors <bors@rust-lang.org>
Thu, 10 Jul 2014 23:26:39 +0000 (23:26 +0000)
commit0e80dbe59ea986ea53cc3caabffd40b2eaee4dc6
tree3044cbdb7fe356d52a07c9048bc431aac3de5c4a
parenta672456c40d28f051ecbdb2caf5bf6733371d494
parent9b9cce2316119a2ffdc9556d410e464b7542d64d
auto merge of #15336 : jakub-/rust/diagnostics, r=brson

This is a continuation of @brson's work from https://github.com/rust-lang/rust/pull/12144.

This implements the minimal scaffolding that allows mapping diagnostic messages to alpha-numeric codes, which could improve the searchability of errors. In addition, there's a new compiler option, `--explain {code}` which takes an error code and prints out a somewhat detailed explanation of the error. Example:

```rust
fn f(x: Option<bool>) {
match x {
Some(true) | Some(false) => (),
None => (),
Some(true) => ()
}
}
```

```shell
[~/rust]$ ./build/x86_64-apple-darwin/stage2/bin/rustc ./diagnostics.rs --crate-type dylib
diagnostics.rs:5:3: 5:13 error: unreachable pattern [E0001] (pass `--explain E0001` to see a detailed explanation)
diagnostics.rs:5  Some(true) => ()
                  ^~~~~~~~~~
error: aborting due to previous error
[~/rust]$ ./build/x86_64-apple-darwin/stage2/bin/rustc --explain E0001

    This error suggests that the expression arm corresponding to the noted pattern
    will never be reached as for all possible values of the expression being matched,
    one of the preceeding patterns will match.

    This means that perhaps some of the preceeding patterns are too general, this
    one is too specific or the ordering is incorrect.

```

I've refrained from migrating many errors to actually use the new macros as it can be done in an incremental fashion but if we're happy with the approach, it'd be good to do all of them sooner rather than later.

Originally, I was going to make libdiagnostics a separate crate but that's posing some interesting challenges with semi-circular dependencies. In particular, librustc would have a plugin-phase dependency on libdiagnostics, which itself depends on librustc. Per my conversation with @alexcrichton, it seems like the snapshotting process would also have to change. So for now the relevant modules from libdiagnostics are included using `#[path = ...] mod`.
src/librustdoc/test.rs