new chapter with examples of diagnostic translation PRs#1621
new chapter with examples of diagnostic translation PRs#1621tshepang wants to merge 2025 commits intorust-lang:mainfrom tshepang:howto-translate
Conversation
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
It used to be a submodule. cf. rust-lang/rust#99603
#1406) Co-authored-by: Yuki Okushi <jtitor@2k36.org> Co-authored-by: Ridwan Abdilahi <riabdila@microsoft.com>
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
Co-authored-by: Joshua Nelson <github@jyn.dev>
* 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 <camelidcamel@gmail.com> * address review comment #1394 (review) * accept review suggestion Co-authored-by: Noah Lev <camelidcamel@gmail.com> * address review comment #1394 (review) * address review comment #1394 (comment) * this breaks markdown * address review comment #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 #1394 (comment) * address review comment #1394 (comment) * accept review suggestion This was reverted by mistake Co-authored-by: Noah Lev <camelidcamel@gmail.com> * address review comment #1394 (comment) * use a more simple fn * address review comment #1394 (comment) Much more clean * nit * accept review suggestion Co-authored-by: Noah Lev <camelidcamel@gmail.com> * 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 <camelidcamel@gmail.com>
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 <github@jyn.dev> Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Noah Lev <camelidcamel@gmail.com>
Also, make link to upstream llvm repo clickable
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
compiler-errors
left a comment
There was a problem hiding this comment.
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.
| > 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.
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.
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.
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.
| - 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.
| - 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.
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.
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 <michael@errs.io>
|
@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.