diff options
| author | bors <bors@rust-lang.org> | 2014-07-10 23:26:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-10 23:26:39 +0000 |
| commit | 0e80dbe59ea986ea53cc3caabffd40b2eaee4dc6 (patch) | |
| tree | 3044cbdb7fe356d52a07c9048bc431aac3de5c4a /src/libsyntax/ext/expand.rs | |
| parent | a672456c40d28f051ecbdb2caf5bf6733371d494 (diff) | |
| parent | 9b9cce2316119a2ffdc9556d410e464b7542d64d (diff) | |
| download | rust-0e80dbe59ea986ea53cc3caabffd40b2eaee4dc6.tar.gz rust-0e80dbe59ea986ea53cc3caabffd40b2eaee4dc6.zip | |
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`.
Diffstat (limited to 'src/libsyntax/ext/expand.rs')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index b7d72ae4deb..b5f7005c2a3 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -58,7 +58,7 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> { None => { fld.cx.span_err( pth.span, - format!("macro undefined: '{}'", + format!("macro undefined: '{}!'", extnamestr.get()).as_slice()); // let compilation continue @@ -567,7 +567,7 @@ fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<Gc<Stmt>> { let marked_after = match fld.extsbox.find(&extname.name) { None => { fld.cx.span_err(pth.span, - format!("macro undefined: '{}'", + format!("macro undefined: '{}!'", extnamestr).as_slice()); return SmallVector::zero(); } |
