-
Notifications
You must be signed in to change notification settings - Fork 522
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
new chapter with examples of diagnostic translation PRs #1621
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Yuki Okushi <[email protected]>
It used to be a submodule. cf. rust-lang/rust#99603
rust-lang#1406) Co-authored-by: Yuki Okushi <[email protected]> Co-authored-by: Ridwan Abdilahi <[email protected]>
Signed-off-by: Yuki Okushi <[email protected]>
Signed-off-by: Yuki Okushi <[email protected]>
Signed-off-by: Yuki Okushi <[email protected]>
Signed-off-by: Yuki Okushi <[email protected]>
Signed-off-by: Yuki Okushi <[email protected]>
Co-authored-by: Yuki Okushi <[email protected]>
Co-authored-by: Joshua Nelson <[email protected]>
* make date-check lightweight This avoids having to write the date twice when updating date-check. Before "As of <-- 2022-07 --> July 2022" After "As of July 2022" * please clippy * update date-check docs * accept review suggestion Co-authored-by: Noah Lev <[email protected]> * address review comment rust-lang#1394 (review) * accept review suggestion Co-authored-by: Noah Lev <[email protected]> * address review comment rust-lang#1394 (review) * address review comment rust-lang#1394 (comment) * this breaks markdown * address review comment rust-lang#1394 (comment) This led to a more robust regex, though making the tool more picky. It also found a wrong date format that was missed. * address review comment rust-lang#1394 (comment) * address review comment rust-lang#1394 (comment) * accept review suggestion This was reverted by mistake Co-authored-by: Noah Lev <[email protected]> * address review comment rust-lang#1394 (comment) * use a more simple fn * address review comment rust-lang#1394 (comment) Much more clean * nit * accept review suggestion Co-authored-by: Noah Lev <[email protected]> * avoid a failed regex Also, test new shape * adjust to new regex (which uses named groups) New regex was introduced by 456008c Co-authored-by: Noah Lev <[email protected]>
This diagram is based on the diagram in Joshua Nelson's talk on bootstrapping at RustConf 2022 [1]. I converted it to Mermaid and made some tweaks to simplify it and bring it closer to bootstrap's terminology, and then Ralf Jung added nodes for copying artifacts. [1]: https://rustconf.com/schedule#bootstrapping-the-once-and-future-compiler Co-authored-by: Joshua Nelson <[email protected]> Co-authored-by: Ralf Jung <[email protected]>
Co-authored-by: Noah Lev <[email protected]>
Also, make link to upstream llvm repo clickable
bbafcf2
to
7a1313c
Compare
Signed-off-by: Yuki Okushi <[email protected]>
Signed-off-by: Yuki Okushi <[email protected]>
Signed-off-by: Yuki Okushi <[email protected]>
7a1313c
to
78c3edc
Compare
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.
Thanks for this. I think we could use this as an opportunity to provide a bit more "motivation" for the various parts of migrating these diagnostic structs if we add more information. Left a bunch of nits..
ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit(); | ||
``` | ||
|
||
> Note that `ecx.struct_span_err` is the [Session::struct_span_err]. |
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.
> Note that `ecx.struct_span_err` is the [Session::struct_span_err]. | |
> Note that `ecx.struct_span_err` calls [Session::struct_span_err]. |
This should also probably link to ecx.struct_span_err
(https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/struct.ExtCtxt.html#method.struct_span_err) so that users can attest this relationship themselves.
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.
yeah, that should have been ultimately calls...
- Replace the code above with this: | ||
|
||
```rust | ||
ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span }); |
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.
Should point to emit_err
in rustdocs. Also, useful to point out that if the user wants to make a diagnostic, but not emit it, they can use create_err
.
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.
tough balance between adding useful info and avoiding the overwhelm... I should find a way to fit create_err
in the reference
ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span }); | ||
``` | ||
|
||
- Create the above type, `errors::ProcMacroDeriveTokens`, |
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.
- Create the above type, `errors::ProcMacroDeriveTokens`, | |
- Add a diagnostic struct, `errors::ProcMacroDeriveTokens`, |
Referring to the [general comments](#general-comments) section above, | ||
follow these changes: | ||
|
||
- Replace the code above with this: |
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.
- Replace the code above with this: | |
- Replace the calls to `struct_span_err` and `emit` with: |
#[derive(Diagnostic)] | ||
#[diag(expand_proc_macro_derive_tokens)] | ||
pub struct ProcMacroDeriveTokens { | ||
#[primary_span] |
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 may be useful to motivate the three important parts of this:
derive(Diagnostic)
diag(FLUENT_SLUG)
- and
primary_span
Maybe why we need these three components, what other components are common, etc?
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 more wanted to have people see the pattern, than do wall-of-text which can overwhelm. The more complete details are in the reference chapters (earlier in the guide).
Co-authored-by: Michael Goulet <[email protected]>
@compiler-errors do you think this is fine to merge now?. |
Update: cf rust-lang/rust#132181 (diag infra currently in limbo, no longer mandatory usage, but examples/clarifications will still be very helpful) |
Sorry, due to me messing up a git operation, we sadly had to force-push the whole commit history of rustc-dev-guide :( If you'd like to update this pull request, you will have to rebase it in a special way onto the new commit history (the new
More context can be found here. |
I found other examples overwhelming, as they tend to handle large parts of rustc crates, so decided to point to these more simple ones I created.