-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 attribute macros format for diagnostic structs without fluent slug #117867
Conversation
The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging. These commits modify the If this was unintentional then you should revert the changes before this PR is merged.
cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki
|
return Ok(()); | ||
match &attr.meta { | ||
// support syntax `#[diag("message ...", code = "E0045", note = "node message")]` | ||
Meta::List(MetaList { path, tokens: token_stream, .. }) => { |
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 is to support:
#[diag("message....")] // or #[diag("message", code = "...", note = "...")]
If it's:
#[diag(label = "message....")]
it will be handled by attr.parse_nested_meta
below.
I'd suggest we only support the late one, which is more consistent with suggestion
, multipart_suggestion
, or we only support #[diag("message....")]
(without extra nested elements), if there are multiple nested elements label =
is required?
@@ -58,9 +56,10 @@ impl<'a> Parser<'a> { | |||
let span = self.token.span; | |||
let mut err = self.sess.span_diagnostic.struct_span_err_with_code( | |||
span, | |||
fluent::parse_inner_doc_comment_not_permitted, |
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.
How do we handle this?
maybe we need a new macro to mark the content need to be translated.
I think this needs an MCP (major change proposal over at https://github.com/rust-lang/compiler-team)? |
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.
+1 from me, but I think it would be nicer to have a smaller crate with fewer diagnostics as an example here instead of rustc_parse, which is quite big and will lead to some merge conflicts
176bb46
to
bf3b14d
Compare
cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki These commits modify the If this was unintentional then you should revert the changes before this PR is merged. The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging.
|
This comment has been minimized.
This comment has been minimized.
|
||
parse_inner_attr_explanation = inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files | ||
parse_inner_attr_not_permitted = an inner attribute is not permitted in this context | ||
.label_does_not_annotate_this = {parse_label_inner_attr_does_not_annotate_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.
How do we support this scenario in the new format?
I think we may support it like this:
#[derive(Diagnostic)]
#[diag(label = "the label...", does_not_annotate_this = "the content can be refer...")]
pub(crate) struct ErrorStruct {
...
pub sugg: Option<SubErrorStruct>,
}
#[derive(Subdiagnostic)]
pub(crate) struct SubErrorStruct {
#[suggestion("{does_not_annotate_this}")
pub span: Span
}
This comment has been minimized.
This comment has been minimized.
728a864
to
9d8105d
Compare
yeah, I fixed the conflict. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
b1820bd
to
1a3dc67
Compare
This comment was marked as resolved.
This comment was marked as resolved.
d5ece88
to
1df013b
Compare
|
1df013b
to
db6553b
Compare
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
☔ The latest upstream changes (presumably #118527) made this pull request unmergeable. Please resolve the merge conflicts. |
14ed478
to
03c8665
Compare
☔ The latest upstream changes (presumably #118692) made this pull request unmergeable. Please resolve the merge conflicts. |
Switching to waiting on author to take action. Seems that an MCP should be appropriate for these changes and also the rust-analyzer comment) suggest to be resolved. Thanks! @rustbot author |
The rust-analyzer related change was committed by accident, I already rollback it. |
03c8665
to
b25a2bb
Compare
☔ The latest upstream changes (presumably #119578) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Apologies it took me so long to get to this. I've left some feedback. As it's been a while, this may be a big rebase, particularly given the many changes to the diagnostic internals that have been happening recently.
} | ||
} | ||
(Some(_slug), Some(_raw_label)) => { | ||
unreachable!("BUG: slug and raw label specified"); |
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 should be an error from the proc macro rather than a unreachable!
.
DiagnosticMessage::FluentRaw(msg) => { | ||
// FIXME(yukang): calculate the `slug` from the raw fluent content, | ||
// The fluent resources are generated by a simple standalone visitor: | ||
// https://github.com/chenyukang/fluent-utils/blob/main/src/visitor.rs#L13-L97 |
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 I still prefer some solution where the compiler is able to emit the reference ftl
rather than needing another tool to extract it. I know that we tried to do this by writing static variables into a section, but we might also be able to do it from the proc macro by writing to the filesystem (which isn't ideal) based on an environment variable.
@@ -44,9 +46,15 @@ pub(crate) struct DiagnosticDeriveVariantBuilder { | |||
/// has the actual diagnostic message. | |||
pub slug: SpannedOption<Path>, | |||
|
|||
/// Label is a the text embedded in the struct attribute and corresponds to the diagnostic |
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.
Maybe message
instead of label
because label
is the term we use for a type of subdiagnostic.
@@ -182,59 +193,116 @@ impl DiagnosticDeriveVariantBuilder { | |||
let name = attr.path().segments.last().unwrap().ident.to_string(); | |||
let name = name.as_str(); | |||
|
|||
let mut first = true; | |||
let mut set_label = false; | |||
let keys = vec!["note", "help", "warning", "suggestion"]; | |||
|
|||
if name == "diag" { |
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.
Would it be simpler to introduce a mutually exclusive diag_new
and re-use some logic, what would parse as slug
becomes message
(or label
as you have it now)?
@@ -601,6 +612,9 @@ pub(super) struct SubdiagnosticVariant { | |||
pub(super) kind: SubdiagnosticKind, | |||
pub(super) slug: Option<Path>, | |||
pub(super) no_span: bool, | |||
/// A subdiagnostic can have a raw_label field, e.g. `#[help("some text")]`. | |||
/// if `slug` is None, this field need to be set. | |||
pub(super) raw_label: Option<LitStr>, |
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.
Can we use an enum for slug
that has a message
or a slug
, to capture the mutual exclusive-ness of these?
@@ -29,6 +29,17 @@ pub(crate) fn new_code_ident() -> syn::Ident { | |||
}) | |||
} | |||
|
|||
pub(crate) fn convert_to_litstr(lit: &proc_macro2::Literal) -> LitStr { |
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.
Why is this necessary?
I think it might be a good idea for @chenyukang, @davidtwco, @oli-obk and myself to talk synchronously sometime soon. We need to come to an agreement to what the long term plan is here and I know I have thoughts about options we have available which would affect whether this PR can be merged as is or would require changes. I'm really excited about this project and want to ensure its success. |
@estebank good idea, I'm ok for online meeting. |
@chenyukang any updates on this? thanks |
cc @Manishearth as you also have opinions on translation infrastructure, there's a summary of what this PR is about in https://hackmd.io/@e0xmMzbUT7SeCAVAVjBv2Q/S1XOUOdQa (the hackmd linked from the main post) |
I've expressed opinions on this before: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Localization.20infra.20interferes.20with.20grepping.20for.20error TLDR: translation files are source code, they have intentionalilty to them, they ought to be commentable, they should be managed by the translation team like source code. It's theoretically possible to have an autogenerate-the-ftl-file workflow that retains this, but you'd need a bunch more design work. At the very very least: we'd need an attribute that allows one to provide context to translators, which turns into a comment in the FTL file. Another common need is organizing the file, it's less important and something people can get without, but definitely something we lose here. This proposal seems to be designed entirely with the needs of compiler devs in mind, without consideration for the needs of translators.
I don't think this is a good idea: there is a distinction between "this is a wording change that's just sprucing stuff up in English" and "this is a wording change that changes the meaning of this slug and needs retranslation". I do recognize that the current system is prone to people making changes that do not notify the translation teams (was hoping to have some automation set up eventually that does this). Furthermore, slugs are meant to be human readable.
This is intentional choice (and common practice in translation environments): people should be carefully considering whether or not the prefix needs to be added when this crops up. So I'm mostly against such a change. If someone who understands the needs of translation teams were to design such a change it could work, but at the moment that's not the case, the most basic ability to comment and organize the translation file is lost. I'd be grudgingly okay with such a change with the following modifications:
Footnotes
|
The background for this:
Split out Fluent from Diagnostics Structs - HackMD
The change on
compiler/rustc_macros/src/diagnostics
are makingDiagnostic
andSubdiagnostic
compatible with the old format and new format, after we migrating all crates, we may need to clean up old code.I made a program to migrate from old format to the new format for each crate automatically(but still need some trivial manual touch), I'd like to get some feedback for parser as a starting point.
r? @davidtwco
Ping @estebank @oli-obk who may also interested on this part.