-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Migrate rustdoc
diagnostics to translatable diagnostics
#112807
base: master
Are you sure you want to change the base?
Migrate rustdoc
diagnostics to translatable diagnostics
#112807
Conversation
r? @jsha (rustbot has picked a reviewer for you, use r? to override) |
@rustbot label +A-translation |
This comment has been minimized.
This comment has been minimized.
src/librustdoc/lib.rs
Outdated
let reported = diag.struct_err(err).emit(); | ||
Err(reported) | ||
} | ||
Err(error) => Err(diag.emit_err(MainError { error })), |
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 think it makes sense to "translate" this -- it's not any better in this current state, IMO. Can you just add diagnostic_outside_of_impl
for this function and remove MainError
?
Ideally we'd change Result<(), String>
into something that's like Result<(), T>
where T: IntoDiagnostic
or something...
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.
After some thought, realized that the error string that we got here comes from Result
, which is in English.
If we would like to make this section translatable, then we need to support translations of Result::Err
. Is this even feasible?
src/librustdoc/messages.ftl
Outdated
couldn't generate documentation: {$error} | ||
.note = failed to create or modify "{$file}" | ||
|
||
rustdoc_compilation_failed = Compilation failed, aborting rustdoc |
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 know this is pre-existing, but it's conventional for diagnostics to be lowercase. Not sure if rustdoc is special in this regard or if this was just an oversight.
rustdoc_compilation_failed = Compilation failed, aborting rustdoc | |
rustdoc_compilation_failed = compilation failed, aborting rustdoc |
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.
Most of the diagnostics in rustdoc are in lowercase (around < 5 that are not).
Shall we set all them to lowercase? @jsha
src/librustdoc/lib.rs
Outdated
} | ||
Err(e) => Err(tcx.sess.emit_err(CouldntGenerateDocumentation { | ||
error: e.error, | ||
file: e.file.display().to_string(), |
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.
Is file
ever actually empty in practice? If so, I think it may be better to represent this as Option<String>
so you can just annotate it with #[note]
instead of having a custom impl IntoDiagnostic<'_> for CouldntGenerateDocumentation
.
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 another alternative that I found, it requires adding another struct for a Subdiagnostic
note.
#[derive(Diagnostic)]
#[diag(rustdoc_couldnt_generate_documentation)]
pub(crate) struct CouldntGenerateDocumentation {
pub(crate) error: String,
#[subdiagnostic]
pub(crate) file: Option<FailedToCreateOrModifyFile>,
}
#[derive(Subdiagnostic)]
#[note(rustdoc_failed_to_create_or_modify_file)]
pub(crate) struct FailedToCreateOrModifyFile {
pub(crate) file: String,
}
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.
Having Option<String>
for the file
field (in the version specified in this review comment) and adding #[note]
to the struct causes compilation failures.
This is because Option<String>
doesn't implement IntoDiagnosticArgs
. Implementing IntoDiagnosticArgs
for Option<String>
is also not allowed due to the orphan rules. Creating a new (wrapped) type for Option<String>
, and then implementing the trait wouldn't work because the Option
is "gone" from the struct field.
CMIIW here :)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
05b2de3
to
d0cf772
Compare
This comment has been minimized.
This comment has been minimized.
d0cf772
to
b5be644
Compare
This comment has been minimized.
This comment has been minimized.
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #114905) made this pull request unmergeable. Please resolve the merge conflicts. |
@nicklimmm this is waiting on you to resolve the conflicts and the CI error. Let me know if you have any updates |
Will catch up on this soon, currently packed with other stuff. |
@nicklimmm any updates on this? thanks |
Diagnostic translation tracking issue: #100717