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

Initial diagnostic API for proc-macros. #44125

Merged
merged 1 commit into from
Aug 31, 2017
Merged

Conversation

SergioBenitez
Copy link
Contributor

@SergioBenitez SergioBenitez commented Aug 28, 2017

This commit introduces the ability to create and emit Diagnostic structures from proc-macros, allowing for proc-macro authors to emit warning, error, note, and help messages just like the compiler does.

The API is somewhat based on the diagnostic API already present in rustc with several changes that improve usability. The entry point into the diagnostic API is a new Diagnostic type which is primarily created through new error, warning, help, and note methods on Span. The Diagnostic type records the diagnostic level, message, and optional Span for the top-level diagnostic and contains a Vec of all of the child diagnostics. Child diagnostics can be added through builder methods on Diagnostic.

A typical use of the API may look like:

let token = parse_token();
let val = parse_val();

val.span
    .error(format!("expected A but found {}", val))
    .span_note(token.span, "because of this token")
    .help("consider using a different token")
    .emit();

cc @jseyfried @nrc @dtolnay @alexcrichton

This commit introduces the ability to create and emit `Diagnostic`
structures from proc-macros, allowing for proc-macro authors to emit
warning, error, note, and help messages just like the compiler does.
@SergioBenitez
Copy link
Contributor Author

r? @nrc

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2017
@nrc
Copy link
Member

nrc commented Aug 30, 2017

@bors: r+

@bors
Copy link
Contributor

bors commented Aug 30, 2017

📌 Commit 8be132e has been approved by nrc

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Aug 30, 2017
Initial diagnostic API for proc-macros.

This commit introduces the ability to create and emit `Diagnostic` structures from proc-macros, allowing for proc-macro authors to emit warning, error, note, and help messages just like the compiler does.

The API is somewhat based on the diagnostic API already present in `rustc` with several changes that improve usability. The entry point into the diagnostic API is a new `Diagnostic` type which is primarily created through new `error`, `warning`, `help`, and `note` methods on `Span`. The `Diagnostic` type records the diagnostic level, message, and optional `Span` for the top-level diagnostic and contains a `Vec` of all of the child diagnostics. Child diagnostics can be added through builder methods on `Diagnostic`.

A typical use of the API may look like:

```rust
let token = parse_token();
let val = parse_val();

val.span
    .error(format!("expected A but found {}", val))
    .span_note(token.span, "because of this token")
    .help("consider using a different token")
    .emit();
```

cc @jseyfried @nrc @dtolnay @alexcrichton
bors added a commit that referenced this pull request Aug 31, 2017
Rollup of 8 pull requests

- Successful merges: #44044, #44089, #44116, #44125, #44154, #44157, #44160, #44172
- Failed merges: #44162
@bors bors merged commit 8be132e into rust-lang:master Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants