-
Notifications
You must be signed in to change notification settings - Fork 537
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(); | ||
``` | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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`. | ||
``` |
There was a problem hiding this comment.
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`.
@Manishearth @estebank Thanks for the feedback! I think I addressed all the comments. |
@bors r+ |
rust-lang/rust#48309 merged |
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