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 info about emitting lints and errors #139

Merged
merged 6 commits into from
May 28, 2018
Merged

Conversation

mark-i-m
Copy link
Member

Since I was just working on this, I thought I would write something up.

We should wait to merge this until rust-lang/rust#48309 merges.

r? @estebank @Manishearth

cc #14 #50

@mark-i-m mark-i-m mentioned this pull request May 22, 2018
15 tasks
Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great overall, thanks for doing this!

src/diag.md Outdated

[errors]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/index.html

Most "session"-like types in the compiler (e.g. [`Session`][session]) have
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to just say Session and ParseSess here.

src/diag.md Outdated
For example, to add a help message to an error, one might do:

```rust,ignore
let snip = sess.codemap().span_to_snippet(sp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an unwrap_or, span_to_snippet returns an Option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to show the more common code of:

let mut err = sess.struct_span_err(sp, "oh no! this is an error!");
// add code to verify that `sp` is not a macro if this is a consideration <...expand explanation of this later...>
if let Some(snippet) = sess.codemap().span_to_snippet(sp) {
    err.span_suggestion(suggestion_sp, "try using a qux here", format!("qux {}", snip));
} else { // in practice this is unlikely to be reached <...add explanation of this later...>
    err.span_help(suggestion_sp, "you could use a qux here instead");
}
err.emit();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// add code to verify that sp is not a macro if this is a consideration <...expand explanation of this later...>

@estebank I didn't quite understand what you meant by this.


I think will just create a new section for suggestions since they will play a big role in the edition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, you can forego that comment. It is a caveat that we'll need to add at some point, as suggestions that do not verify wether the current context is mixing macros can lead to very incorrect suggestions (like in #39450). This is not a problem under normal circumstances, but adding a check for this in the documentation could go a long way. Don't need to add it now though.

src/diag.md Outdated
}
```

### Edition Lints
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Edition-gated lints", there are more kinds of edition lints.

src/diag.md Outdated
.span_suggestion(other_sp, "try using a qux here", format!("qux {}", snip))
.emit();
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also include some stuff on suggestion applicabilities here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to block too much on this, once this PR is merged it can be expanded more iteratively.

error: aborting due to previous error

For more information about this error, try `rustc --explain E0999`.
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add explanation:

In some cases, like when the suggestion spans multiple lines or when there are multiple suggestions, the suggestions are displayed on its own:

error[E0999]: oh no! this is an error!
 --> mycode.rs:3:5
  |
3 |     sad()
  |     ^
help: try using a qux here:
  |
3 |     qux sad()
  |     ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0999`.

@mark-i-m
Copy link
Member Author

@Manishearth @estebank Thanks for the feedback! I think I addressed all the comments.

@estebank
Copy link
Contributor

@bors r+

@mark-i-m
Copy link
Member Author

rust-lang/rust#48309 merged

@mark-i-m mark-i-m merged commit dbac00d into rust-lang:master May 28, 2018
@mark-i-m mark-i-m deleted the diag branch June 15, 2019 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants