-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ce78bfb
begin on no-fluent-errors
chenyukang 46c8b80
more cleanup on diags
chenyukang 670d1a1
more updates on parser
chenyukang c9f8439
remove messages.ftl from parser
chenyukang 653159c
remove parser fluent from rustc_expand
chenyukang d768dbb
fix diagnostic derive
chenyukang bb2eb3f
add FluentRaw to represent fluent raw content
chenyukang a173063
find fluent resource from hash slug
chenyukang b25a2bb
fix conflicts in diagnostics
chenyukang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,17 +28,17 @@ impl<'a> DiagnosticDerive<'a> { | |
let preamble = builder.preamble(variant); | ||
let body = builder.body(variant); | ||
|
||
let init = match builder.slug.value_ref() { | ||
None => { | ||
span_err(builder.span, "diagnostic slug not specified") | ||
let init = match (builder.slug.value_ref(), builder.label.value_ref()) { | ||
(None, None) => { | ||
span_err(builder.span, "diagnostic slug or label is not specified") | ||
.help( | ||
"specify the slug as the first argument to the `#[diag(...)]` \ | ||
attribute, such as `#[diag(hir_analysis_example_error)]`", | ||
attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = \"the message ..\")]", | ||
) | ||
.emit(); | ||
return DiagnosticDeriveError::ErrorHandled.to_compile_error(); | ||
} | ||
Some(slug) | ||
(Some(slug), None) | ||
if let Some(Mismatch { slug_name, crate_name, slug_prefix }) = | ||
Mismatch::check(slug) => | ||
{ | ||
|
@@ -48,7 +48,7 @@ impl<'a> DiagnosticDerive<'a> { | |
.emit(); | ||
return DiagnosticDeriveError::ErrorHandled.to_compile_error(); | ||
} | ||
Some(slug) => { | ||
(Some(slug), None) => { | ||
slugs.borrow_mut().push(slug.clone()); | ||
quote! { | ||
let mut diag = rustc_errors::DiagnosticBuilder::new( | ||
|
@@ -58,6 +58,18 @@ impl<'a> DiagnosticDerive<'a> { | |
); | ||
} | ||
} | ||
(None, Some(raw_label)) => { | ||
quote! { | ||
let mut diag = rustc_errors::DiagnosticBuilder::new( | ||
dcx, | ||
level, | ||
DiagnosticMessage::FluentRaw(#raw_label.into()) | ||
); | ||
} | ||
} | ||
(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 commentThe reason will be displayed to describe this comment to others. Learn more. This should be an error from the proc macro rather than a |
||
} | ||
}; | ||
|
||
let formatting_init = &builder.formatting_init; | ||
|
@@ -88,6 +100,7 @@ impl<'a> DiagnosticDerive<'a> { | |
} | ||
} | ||
}); | ||
|
||
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) { | ||
imp.extend(test); | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.